Windows – Command Line Loop to Run Command on All Files

command lineimagemagickwindows

I'm assuming this is fairly easy to do, but I have zero experience with Windows's command line utilities. Basically, I need to iterate over all files in a directory (great if it can do sub-directories, but I can run it on each of the 5 directories if need be), get the name as a variable, and have it run

"C:\Program Files\ImageMagick-6.7.6-Q16\convert.exe" -compress LZW 
   -colorspace Gray -colors 32 file_var file_var

I saw Dynamically name files in a command prompt for loop. Would I be able to use that (swapping the SET… with the above command)? The space on the computer in question is beyond limited so I can't perform a backup prior to running this at this stage (bad, I know).

Best Answer

Weird, there was a response that had the recursive part.

Well, per How to Loop Through Files Matching Wildcard in Batch File, I was able to achieve this. Here is how it was performed:

 cd path_to_root
 for /R %%f in (*.tif) do (
 "C:\Program Files\ImageMagick-6.7.6-Q16\convert.exe" -compress LZW 
    -colorspace Gray -colors 32 "%%f" "%%f"
 )
Related Question