Run exiftool across multiple spefici file types - exiftool

is there a way to use exiftool command on all files with specific extensions inside a folder?
E.g.
exiftool -overwrite_original -all= *.jpg *.png *.jpeg
The problem of the command above is that it gives me:
no matches found: *.png
because there are not .png images inside my folder, but I want the command to run anyway on all files with other extensions.
Thanks

Use the -ext (extension) option and a dot to indicate the current directory, e.g. exiftool -overwrite_original -all= -ext jpg -ext jpeg -ext png .
This option becomes especially import when you add the recurse options (-r) as wild cards won't work like that when you recurse (see Common Mistake #2).

Related

Setting Tar compression level in Win10

I created a powershell command in order to compress mdb files from a certain folder. The structure looks like this:
C:\Projects\MySoftware\templates\A\a.mdb
C:\Projects\MySoftware\templates\B\b.mdb
C:\Projects\MySoftware\templates\C\c.mdb
Basically I want that my archive must contains the directories with "templates" as root node. So:
templates\A\a.mdb
templates\B\b.mdb
templates\C\c.mdb
And in PowerShell
powershell -Command "$pa = 'C:\Projects'; Set-Location C:\Projects\MySoftware\; gci -Path templates -Recurse -Include *.mdb | sort LastWriteTime | ForEach-Object { cd 'C:\Projects\MySoftware\'; $fn = $_.Fullname; tar rf BASetupUpdate.tgz $($fn.Replace('C:\Projects\MySoftware\','')) }"
The tar creates correctly the archive but without compression. I'm struggling with command line and help in order to set the compression level.
You need to add the z option to compress, which cannot be used with r, only c. You would need to make a list of all the things you want to put in the tar file, and use a single invocation of the tar command with all of those names. You cannot incrementally add files to a compressed tar.gz (or .tgz if you prefer) archive. So something like:
tar -czf archive.tgz file1 file2 ... filen
As for the compression level, you can add --option gzip:compression-level=9. However to start, you should leave it at the default level and see if that meets your needs. Higher compression levels can take much more time for a small reduction in size.

How to compress all files in a directory using 7-zip?

How do you archive all files (including ones without extensions) in a directory without archiving of the subdirectories using 7-zip command tool (7z.exe)?
If I use the wildcard with a dot (*.*) it works but only for files with extensions. Using * (or not using the wildcard at all) does not work even with the -r- switch (which is supposed to be then default according to the help file), since it archives everything in the source directory recursively. I just need to archive all files (some may not have extensions) in the immediate directory (no subfolders and no recursion). Any ideas?
The following commands do not work:
7z.exe a c:\output.7z c:\input -r-
7z.exe a c:\output.7z c:\input\* -r-
I am calling 7-zip from a PowerShell script, if this matters.
7-Zip will take an array of file objects for the input, so this should work:
& 7z.exe a C:\output.7z (Get-ChildItem C:\Input\* -File)

Batch processing Pandoc conversions in Windows

I am trying to convert a large number of HTML files into Markdown using Pandoc in Windows, and have found an answer on how to do this on a Mac, but receive errors when attempting to run the following in Windows PowerShell.
find . -name \*.md -type f -exec pandoc -o {}.txt {} \;
Can someone help me translate this to work in Windows?
to convert files in folders recursively try this (Windows prompt command line):
for /r "startfolder" %i in (*.htm *.html) do pandoc -f html -t markdown "%~fi" -o "%~dpni.txt"
For use in a batch file double the %.
Most of the answers here (for ... solutions) are for cmd.exe, not PowerShell.
mb21's answer is on the right track, but has a bug with respect to targeting each input file; also, it is hard to parse visually.
The functionally equivalent PowerShell command is:
Get-ChildItem -File -Recurse -Filter *.md | ForEach-Object {
pandoc -o ($_.FullName + '.txt') $_.FullName
}
Endoro's answer is great, don't get confused by the parameters added to %i.
For helping others, I needed to convert from RST (restructured text) to dokuwiki syntax, so I created a convert.bat with:
FOR /r "startfolder" %%i IN (*.rst) DO pandoc -f rst -t dokuwiki "%%~fi" -o "%%~dpni.txt"
Works for all rst files in folders and subfolders.
If you want to go recursively through a directory and its subdirectories to compile all the files of type, say, *.md, then you can use the batch file I wrote in answer to another question How can I use pandoc for all files in the folder in Windows? . I call it pancompile.bat and the usage is below. Go to the other answer for the code.
Usage: pancompile DIRECTORY FILENAME [filemask] ["options"]
Uses pandoc to compile all documents in specified directory and subdirectories to a single output document
DIRECTORY the directory/folder to parse recursively (passed to pandoc -s);
use quotation marks if there are spaces in the directory name
FILENAME the output file (passed to pandoc -o); use quotation marks if spaces
filemask an optional file mask/filter, e.g. *.md; leave blank for all files
"options" optional list of pandoc commands (must be in quotation marks)
Minimal example: pancompile docs complete_book.docx
Typical example: pancompile "My Documents" "Complete Book.docx" *.md "-f markdown -t docx --standalone --toc"
Using the powershell built-in gci:
gci -r -i *.md |foreach{$docx=$_.directoryname+"\"+$_.basename+".docx";pandoc $_.name -o $docx}
from https://github.com/jgm/pandoc/issues/5429
I created a python script that I've been using to convert a tree of markdown files into a single output file. It's available on github:
https://github.com/andrewrproper/pandoc-folder

Compressing only files using 7z without preserving the path

I am using 7z command line executable to zip files, but I see that while adding to an archive the path of the files is preserved in the archive.
So if I do
7z a -tzip myzip.zip dir1\dir2\*
the archive myzip.zip will contain the path dir1\dir2. I do not want this, rather I want only the files to be added to the zip file without the paths being preserved.
I searched quite a bit but do not seem to find any way of doing this, maybe I am missing something obvious?
Thanks
Just add a dot before the path, i.e.
7z a -tzip -r myzip.zip .\Relative\Dir\*
Give the full path. That should work. Not the relative path from the current location.
For example, I give the below, where I want the files in the man5 folder to be archived.
$ 7z a -tzip myzip.zip /home/pradeeban/Desktop/man4/man5/*
The zip contained only the files, without the directories.
Then I gave only the relative path. It had the directories, inside the zip.
$ 7z a -tzip myzip.zip Desktop/man4/man5/*
Tried with Linux (Ubuntu 12.04). Not sure whether that differs from Windows.
I discovered a way to do this by using a relative path:
7z a -tzip myzip.zip %CD%\dir1\dir2\*
%CD% is how you get the current path in a Windows batch file, but it also works from the command line. More info about Capturing the current directory from a batch file.
As explained in related question in 7-zip user FAQ, 7z stores paths relative to working directory, so you will need to first cd to desired top-level directory for archive and run 7-zip from here.
cd dir1\dir2\
7z a -tzip myzip.zip *
If you run it from script and don't want to affect it with changed directory, use directory push/pop facilities available in your shell of choice or run cd+7-zip in spawned process to avoid affecting your entire script with changed directory. For example, using Windows' start that would be:
start /D dir1\dir2\ /wait 7z a -tzip myzip.zip *
This worked for me
Consider folder structure like C:\Parent\SubFolders..... And you want to create parent.zip which will contain all files and folders C:\Parent without parent folder [i.e it will start from SubFolders.....]
cd /D "C:\Parent"
"7z.exe" a Parent.zip "*.*" -r
This will create Parent.zip in C:\Parent

Change file extensions of multiple files in a directory with terminal/bash?

I'm developing a simple launchdaemon that copies files from one directory to another. I've gotten the files to transfer over fine.
I just want the files in the directory to be .mp3's instead of .dat's
Some of the files look like this:
6546785.8786.dat
3678685.9834.dat
4658679.4375.dat
I want them to look like this:
6546785.8786.mp3
3678685.9834.mp3
4658679.4375.mp3
This is what I have at the end of the bash script to rename the file extensions.
cd $mp3_dir
mv *.dat *.mp3
exit 0
Problem is the file comes out as *.mp3 instead of 6546785.8786.mp3
and when another 6546785.8786.dat file is imported to $mp3_dir, the *.mp3 is overwritten with the new .mp3
I need to rename just the .dat file extensions to .mp3 and keep the filename.
Ideas? Suggestions?
Try:
for file in *.dat; do mv "$file" "${file%dat}mp3"; done
Or, if your shell has it:
rename .dat .mp3 *.dat
Now, why your command didn't work: first of all, it is more than certain that you only had one file in your directory when it was renamed to *.mp3, otherwise mv would have failed with *.mp3: not a directory.
And mv does NOT do any magic with file globs, it is the shell which expands globs. Which means, if you had this file in the directory:
t.dat
and you typed:
mv *.dat *.mp3
the shell would have expanded *.dat to t.dat. However, as nothing would match *.mp3, the shell would have left it as is, meaning the fully expanded command is:
mv t.dat *.mp3
Which will create a file named, literally, *.mp3.
If, on the other hand, you had several files named *.dat, as in:
t1.dat t2.dat
the command would have expanded to:
mv t1.dat t2.dat *.mp3
But this will fail: if there are more than two arguments to mv, it expects the last argument (ie, *.mp3) to be a directory.
For anyone on a mac, this is quite easy if you have BREW, if you don't have brew then my advice is get it. then when installed just simply do this
$ brew install rename
then once rename is installed just type (in the directory where the files are)
$ rename -s dat mp3 *