How to loop through folders and rename extensions in a batch file?
Solution 1:
You are not applying the for
command to the ren
action.
for /r "E:\test\" %%G in (*.jpeg) do ren "%%~G" *.png
You need to change %%
to %
if you are doing this interactively, and not in a batch file.
The ~
strips quotes, which are re-added, to avoid any possible errors with paths which contain spaces.
Solution 2:
Or, if you want a slightly shorter one-liner, here's how do to it with a combination of the REN
commmand and the GLOBAL
commmand in JP Software's TCC/LE:
GLOBAL REN *.JPEG *.PNG
Use GLOBAL
's /I
option if you want to ignore any non-zero exit codes from the REN
command, of course.