Jeremy Stein - Brain

« »

Recursively expand compressed files

If you want to know something about a file which may be buried in a .zip or .jar file somewhere. Worse, it may be in a .war inside a .tar inside a .gz somewhere. A brute force method for finding these files is just to expand everything recursively.

Here’s a batch file for doing that with 7-Zip on Windows XP:

Name it “expand.bat”

@echo off
for /r %1 %%f in (*.7z, *.zip, *.war, *.ear, *.gzip, *.gz, *.bz2, *.tar, *.rar, *.arj, *.lzh, *.z, *.cpio) do (
  echo %%f
  "C:\Program Files\7-Zip\7z.exe" x -y -o"%%f-expanded" "%%f" > nul
  rem del "%%f"
  call expand.bat "%%f-expanded"
)

It takes one parameter with the path.

Uncomment the del if that’s what you want it to do. You may want to change the pattern list it’s looking for. In my case, I didn’t want all the .jars. This correctly handles spaces in filenames on XP. NT and 9x work differently.

It’s probably easier to do this with cygwin’s find rather than a Windows batch file.

April 3, 2008 No Comments.

No Comments

Be the first to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Why ask?

« »