user2534449
user2534449

Reputation: 431

unrar from subfolders and rename to parent folder

With a batch file I'd like to be able to unrar all .rar files in subfolders from one specified folder "c:\files". There is a single .txt file inside each rar file that I need to be renamed to it's original rar folder name, this file needs to be with it's original rar file. I'll try to explain..

c:\files\rarfolder1\1.rar
c:\files\rarfolder2\2.rar
c:\files\rarfolder3\3.rar
c:\files\rarfolder4\4.rar

Then becomes

c:\files\rarfolder1\rarfolder1.txt
c:\files\rarfolder2\rarfolder2.txt
c:\files\rarfolder3\rarfolder3.txt
c:\files\rarfolder4\rarfolder4.txt

The folder locations might change as well as the file types inside the rar files.

Upvotes: 1

Views: 1250

Answers (1)

Endoro
Endoro

Reputation: 37569

This might work for you on the command line:

for /r "c:\files" %a in (*.rar *.txt) do @for %i in ("%~pa.") do @if /i "%~xa"==".rar" (echo winrar -x "%~fa") else echo ren "%~fa" "%~ni%~xa"

Upvotes: 2

Related Questions