How to Batch change file extensions within subfolders
batch-file, cmd, renaming
Solution
If I understand correctly that you only want to rename the files from `.png` to `.jpg`, and not convert them, you could use the following batch code:
@ECHO OFF
PUSHD .
FOR /R %%d IN (.) DO (
cd "%%d"
IF EXIST *.png (
REN *.png *.jpg
)
)
POPD
Update: I found a better solution here that you can run right from the command line (use `%%f` in stead of `%f` if using this inside a batch file):
FOR /R %f IN (*.png) DO REN "%f" *.jpg
Note that the above will process the current directory and its subdirectories. If necessary, you can specify an arbitrary directory as the root, like this:
FOR /R "D:\path\to\PNGs" %f IN (*.png) DO REN "%f" *.jpg
Problem
I am very new to Command Prompt, and only started using it as of 1 day ago. I have a folder in a location, for example `C:\Users\Administrator\Desktop\Images`, and inside that folder there is roughly 650 sub-folders, each containing around 20 images, a mix of JPG's and PNG's. I am looking for a command line for CMD which will go through all sub folders and change each `.png` file into a `.jpg` file. I have done a little research and found some information, however it is very hard to follow and understand, and I am still unable to do it. I am wanting to keep the file names, however change each file extension from a `.png` to a `.jpg`. I understand that for 1 folder, the line is something like `ren *.png *.jpg`. However, this does not apply changes to subfolders.