Batch script to rename file extension recursively

2

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

The command I made is so (ren * .rar * .cbr) That way I just rename the files to the root but not the ones in the subfolders below.

Because there are many subfolders, the script is ideally recursive in order to visit all subfolders within the root.

    
asked by anonymous 16.09.2018 / 22:57

2 answers

0

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 parameter will make for is recursive, so it will cycle through all subfolders.

Referral link

    
17.09.2018 / 11:26
0

1. Try to get the path and name of file For using /F + Dir /S ...

Drive and Directory by turning the commands on the Drive and Directory pointed to in the command.

On the command line:     

CD /D D:\Downloads\ 
For /F "tokens=*" %i in ('^<nul dir /o-d /on /b /S "*.rar"') do ren "%~i" "%~ni.cbr"

In the bat / cmd file:

CD /D D:\Downloads\ 
For /f "tokens=*" %%i in ('^<nul Dir /o-d /on /b /S "*.rar"') do ren "%%~i" "%%~ni.cbr"
    
08.12.2018 / 20:55