Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Batch file extracting all files from nested archives

$
0
0

I have managed to leverage a powerful forfiles command line utility with the mighty 7z compression program.

Below is a simple batch file extracting all files from nested archives hidden at any depth inside other archives and/or folders. After the extraction each archive file turns into a folder having the archive file name. If, for example, there was an "outer.rar" archive file containing nothing but an "inner.zip" archive with only "afile.txt" inside, "outer.rar" becomes "...\outer.rar\inner.zip\afile.txt" file system path.

@echo off
rem extract_nested_archives.bat
move %1 "%TMP%"\%2
md %2
7z x -o%1 -y %TMP%\%2
del "%TMP%"\%2
for %%a in (zip rar jar z bz2 gz gzip tgz tar lha iso wim cab rpm deb) do forfiles /P %1 /S /M *.%%a /C "cmd /c if @isdir==FALSE extract_nested_archives.bat @path @file"

ARCHIVES ARE DELETED DURING THE EXTRACTION! Make a copy before running the script!

"7z.exe" and "extract_nested_archives.bat" should be in folders available via the %PATH% environment variable.

The first parameter of extract_nested_archives.bat is the full path name of the archive or folder that should be fully expanded; the second parameter is just the archive or folder name without the path. So you should run "c:\temp\extract_nested_archives.bat c:\temp\outer.rar outer.rar" from the command line to completely expand "outer.rar". "c:\temp" must be the current folder.


Best regards, 0x000000AF


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>