How do I batch recursive imagemagick JPGs into PNG in a folder?

I saw these posts:

  • mogrify - how do you recurse through subfolders in Windows
  • Using imagemagick to identify all files in multiple subfolders
  • https://stackoverflow.com/questions/30414346/batch-command-for-imagemagick-to-convert-all-files-in-a-directory-and-sub-direct
  • https://stackoverflow.com/questions/784057/run-a-simple-command-using-powershell-recursively-on-a-directory

But all of the commands in it result in errors. Such as:

PS D:\> find . -name '*.png' -exec mogrify -format jpg {} +
FIND: Parameter format not correct
PS D:\> for /r . %a in (*.png) do mogrify -resample 90 -format jpg "%~a"
At line:1 char:4
+ for /r . %a in (*.png) do mogrify -resample 90 -format jpg "%~a"
+    ~
Missing opening '(' after keyword 'for'.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword

PS D:\> for(/r . %a) in (*.png) do mogrify -resample 90 -format jpg "%~a"
At line:1 char:13
+ for(/r . %a) in (*.png) do mogrify -resample 90 -format jpg "%~a"
+             ~
Missing statement body in for loop.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingLoopStatement

PS D:\> for(/r . %a) {in (*.png) do mogrify -resample 90 -format jpg "%~a"}
/r : The term '/r' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:5
+ for(/r . %a) {in (*.png) do mogrify -resample 90 -format jpg "%~a"}
+     ~~
    + CategoryInfo          : ObjectNotFound: (/r:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS D:\> magickrec . 90% png jpg
magickrec : The term 'magickrec' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ magickrec . 90% png jpg
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (magickrec:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS D:\>

I don't have enough reputation to comment/etc. on any questions here on superuser, so I cannot reply to anything. Also, I want to do this universally, so don't give me static paths like "D:" I want it in current directory, so I can use the command anywhere. In addition, the ImageMagick command executed should be mogrify NOT convert.


The command I needed to run is as follows:

dir -Filter *.png -Recurse | %{mogrify -format jpg $_.FullName}

Executing this in the folder you want it to will mogrify all files in the current directory and in any directories in it. If you want to delete all of the PNGs that are left behind after, you should use...

dir -Filter *.png -Recurse | del

I'd rather be able to Shift + Right Click and open PowerShell in any directory I want to do this in.

If the folder is open in Explorer, you can just type cmd where the file path is normally given and then press Enter to open a command window (i.e. not PowerShell) in that folder. The batch command to do what you are looking for would be e.g.:

for /r . %a in (*.jpg) do (magick mogrify -resample 90 -format png "%~a")

as already noted in your question.

(This answer skips a PowerShell solution, as one is already provided in the self-answer.)