I want to extract all .zip's and .rars in a folder and its children
The structure is like this:
MAIN_FOLDER
-A folder
- a.zip
-a.rar
-B folder
- b.zip
-b.rar
-C folder
....
...
I tried already this, which did not work
FOR /D /r %%F in ("*") DO (
pushd %CD%
cd %%F
FOR %%X in (*.rar *.zip) DO (
"C:\Program Files\7-zip\7z.exe" x %%X
)
popd
)
I use Windows and have 7-Zip installed.
Additional Question: Would it be possible to save all the extracted files from the last children (a.rar, b.rar) in one and the same folder (main folder)?
Best Answer
The Script:
Explanation:
This performs a loop for each file returned by the command
dir /b /s *.zip *.rar
. The/s
tellsdir
to recurse into subdirectories and/b
prints in bare format.The filename is stored in the
%%I
variable for use later. If you were typing this at the prompt, you would use%I
instead.This performs the extraction. The argument
-o"%%~dpI"
extracts the file into the same directory where the archive resides. Other options:-o"%%~dpI"
— Extracts into the directory where the archive resides.-o"%%~dpnI"
— Creates a new directory in the hierarchy named after the archive and extracts there (that is,AFolder\archive.zip
extracts intoAFolder\archive\
).-o"%%~nI"
— Creates a new directory in the current directory named after the archive and extracts there (that is,AFolder\archive.zip
extracts into.\archive\
).Omit the
-o
argument — Extracts into the current directory.Example: