The problem with your code is, as @bgalea pointed out, that batch uses %%a
instead of %a
.
However, while this fixes the syntax of your code, there is still an error. Renaming a file to a different extension doesn't actually convert the file, for example you can't rename a .txt
file to .mp4
and expect it to play a video.
Unfortunately, windows has no native way to convert images. This means that you'll need a 3rd party tool, for example ImageMagick (free). If you have ImageMagick installed, you can use the convert command, like this:
@ECHO OFF
FOR /f "delims=*" %%a IN ('dir *.jpg /b /s') do convert "%%a" "%%~dpna.png"
To delete the files after conversion:
@ECHO OFF
FOR /f "delims=*" %%a IN ('dir *.jpg /b /s') do (
convert "%%a" "%%~dpna.png"
del "%%a"
)
EDIT
Ok, so after trying to get ImageMagick to work I looked for an alternative, and found GraphicsMagick, which is available here. After Installing this, I updated the script, and this time it worked.
@ECHO OFF
FOR /f "delims=*" %%a IN ('dir *.jpg /b /s') do (
"C:\Program Files (x86)\GraphicsMagick-1.3.23-Q16\gm.exe" convert "%%a" "%%~dpna.png"
del "%%a"
)
Please note that you should make sure your gm.exe is located at the same path as the one given above, if not you should edit the path in the script.