mogrify - how do you recurse through subfolders in Windows

I thought there was a simple switch in mogrify command options that tells it go through subfolders as well. I didn't find any. On Linux, the "find" command seems to do the trick, how do you do this on Windows?

magick mogrify -resample 72 -resize 700x700 -format png -path "C:\ImageMagick-7.0.8-Q16\dest" *.*

works but I need it to recurse through subfolders as well. What's the simplest way to do that?

Ideally, I'm looking for the source directory structure to be retained in destination but with the processed images only.


ImageMagick Mogrify Files Recursively - Windows

You can use a FOR /R loop to iterate the files starting from the root directory the files reside and then run those over the commands accordingly as per the below example against each file.

If you omit the -path parameter it seems that it will run against the original files where they reside. So for a simple solution to retain the original structure from the original source, consider simply copying the original root folder of the source files to a new location and then rename that folder.


Example Command

Note: Be sure to replace C:\Source\Folder\Root to be the exact folder where the files or file subfolders reside that it will recurse to run the command operations against those files.

for /r "C:\Source\Folder\Root" %a in (*.*) do mogrify -resample 72 -resize 700x700 -format png "%~a"

Example Command (with delete)

for /r "C:\Source\Folder\Root" %a in (*.*) do mogrify -resample 72 -resize 700x700 -format png "%~a" && IF NOT [%~Xa]==[.png] DEL /Q /F "%~a"

Further Resources

  • FOR /R
  • Batch Substitutions (FOR /?)

    In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax:

    %~xI        - expands %I to a file extension only
    
  • mogrify

  • Del