Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically unzip archives in their own directories on Windows with a DOS command?

There are many ways to unzip archives on Unix:

  • How do you recursively unzip archives in a directory and its subdirectories from the Unix command-line?
  • Unzip a bunch of zips into their own directories

The goal is to find all archives and uncompress them in their own directory (where each archive is found) on Windows.
Optional:

  • remove the archive after unzip.
  • record any error message if one archive has any issue during unzip.

I am looking for a plain DOS command line, using, for instance, 7z.exe (which is included in the portable version of PeaZip).

like image 509
VonC Avatar asked Apr 11 '12 14:04

VonC


1 Answers

I took a command-line from this thread of the sevenzip project, with a small modification:

FOR /R %I IN (*src.zip) DO (C:\apps\peazip_portable-3.8.WINDOWS\res\7z\7z.exe x "%I" -aoa -o"%~dpI\*" |c:\windows\system32\find.exe "Everything is Ok" >nul  &&DEL /F "%I" ||ECHO.%I : EXTRACT FAIL - ARC NOT DELETED >>ERR.TXT)

(multi-line for visibility)

FOR /R %I IN (*src.zip) DO ( \
  C:\apps\peazip_portable-3.8.WINDOWS\res\7z\7z.exe x "%I" -aoa -o"%~dpI\*" 
  |c:\windows\system32\find.exe "Everything is Ok" >nul &&DEL /F "%I"
  ||ECHO.%I : EXTRACT FAIL - ARC NOT DELETED >>ERR.TXT)

Notes:

  • I prefer specifying "c:\windows\system32\find.exe" instead of just FIND, because I have other 'find.exe' on my PATH (from msysgit, or gow).
  • remove the '&&DEL /F "%I"' part if you want to keep the archives in place.

I just unzipped 470 "src.zip" from the Rational Team Concert SDK in two minutes with that one-liner!

like image 124
VonC Avatar answered Oct 27 '22 10:10

VonC