Page 1 of 1

Using 7-zip Command Line to Unzip Multiple Folders

Posted: 08 Feb 2020 21:51
by thaum2u
I have a bunch of videos that were downloaded via BitTorrent. Most of them were broken up into multiple segments in their individual folders. I am trying to create a batchfile that will allow me to drag and drop multiple folders onto it, and then if it finds a .RAR file in a folder, it will uncompress the .RAR file, then go onto the the next folder and do the same.

The segments look like this:

this.is.the.file.name.rar
this.is.the.file.name.r00
this.is.the.file.name.r01
this.is.the.file.name.r02
this.is.the.file.name.r03
...Etc...

So far, I can only get 7z (the 7-Zip command line program) to un-rar a .RAR if I have the batchfile in he same folder as the .RAR and only when I drag and drop the .RAR onto the batchfile, which doesn't provide any functional benefit.

Here is the batchfile so far (hardly even a batchfile yet):

@echo off
"C:\Program Files\7-Zip\7z.exe" x -r *.rar
echo.
pause

I can't figure out how to tell 7z how to open up a folder to find the .RAR, nor how to have it go to another folder after, if I drag and drop multiple folders onto it.

Even if I could get it to work by dragging just one folder at a time to it, I'd be happy.

If anyone needs to see the command and switch list instructions for 7z, here is a text file of all of them for the newest stable version of 7z:

http://noyou.net/7zip/7z.exe_CMD_Instructions.txt

Re: Using 7-zip Command Line to Unzip Multiple Folders

Posted: 09 Feb 2020 10:56
by thaum2u
I got help somewhere else. Here is my solution if anyone cares:

Code: Select all

@echo off

rem  This batchfile allows for dragging multiple folders to it. It then checks each folder (one 
rem  at a time) to see if there is a .RAR file in it, and if there is, it uses 7-Zip's command 
rem  line program, 7z.exe, to extract whatever is in the compressed .RAR file. If it finds 
rem  a Subs folder, it goes into it and looks for another .RAR, etracts it if it is there, then 
rem  continues on...  Obviously, the program 7z.exe has to be in the C:\Program Files\7-Zip\
rem  folder for this to work.

set CTR=0

:EXTRACT_LOOP
if _%1==_ goto :END
set /a CTR=%CTR%+1
pushd "%1"
if not exist *.rar goto :CONTINUE_LOOP
"C:\Program Files\7-Zip\7z.exe" x -y *.rar
if exist %1\Subs\*.* goto PROCESS_SUBTITLES

:CONTINUE_LOOP
popd
shift
goto :EXTRACT_LOOP

:PROCESS_SUBTITLES
cd Subs
if not exist *.rar goto :CONTINUE_LOOP
"C:\Program Files\7-Zip\7z.exe" x -y *.rar
cd..
goto CONTINUE_LOOP

:END
echo.
echo %CTR% files were processed!
echo.
pause

Re: Using 7-zip Command Line to Unzip Multiple Folders

Posted: 12 Feb 2020 18:08
by xyz
I literally just created an account here to thank you for this.

I was having this exact same issue, as I have downloaded whole seasons, with each episode comprised of multiple rar files. So to unzip/unrar an entire season, was an extreme pain in the butt, to say the least.

Once again, THANK YOU very much.