Batch script to rename file extension recursively

Asked

Viewed 1,953 times

3

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

The command I made is like this ( Ren *.rar *.cbr) So it just renames it to the root files but not the ones that come next in the subfolders.

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

3 answers

1

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

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

The parameter /R will make it recursive, so it will go through all subfolders.

Reference link

0


The command where return listing the full path of the files, capture this output in a for to rename the extension.

An option of a looping for with the where recursive=/r for rename as extension


:: No arquivo bat/cmd :: 
   @echo off
   for /f "tokens=*" %&i in ('where /r "D:\Download" "*.rar"')do rename "%%~i" "%%~ni.cbr"  

:: Na linha de comando :: 
   for /f "tokens=*" %i in ('where /r "D:\Download" "*.rar"')do @rename "%~i" "%~ni.cbr"  


1. Try to get the way and name of filing cabinet target in a For using /F + Dir /S...

2. In charge CD add /D (enters and remains in the Drive and Directory running the commands on Drive and Directory pointed in command.


On the command line:


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

-4

The BAT filename within multiple folders works 100% created from these examples shown here :: for /f "tokens=" %i in ('Where /r "G: TXT" ".txt.igvm"') of the name "%~i" "%~ni." (The idea here is to rename cancelling the extension .igvm of the rensomware)

Due to a rensomware problem, this virus encrypts the most common files by adding the . igvm extension. I managed to rename all files using this BAT, then try to recover the original form of the files. txt com (Easeus Data Recovery Wizard) to be opened again by windows notepad. But I did not succeed in restoring my personal files. Thank you to everyone who contributed in this post.

[email protected]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.