Sunday, 2 June 2019

windows - Command Line loop to run command on all files in a directory (plus sub directories, if possible


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).



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"
)

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...