windows – Batch script to rename file extensions recursively

Question:

I need a script in bat that allows renaming all files with EXTENSION *.rar to *.cbr , you need to rename any file in the subfolders from the root directory D:\Downloads.

The command I made is like this (ren *.rar *.cbr) This way I just rename files from the root but not the ones that come next in the subfolders.

As there are many subfolders, the ideal is for the script to be recursive in order to visit all subfolders within the root.

Answer:

You can use the for command.
See if this example meets your needs:

CD D:\Downloads\
For /R %%G in (*.rar) do Echo REN "%%G" "%%~nG.cbr"

The /R switch will make for recursive so it will cycle through all subfolders.

Reference Link

Scroll to Top