1

I'm running Windows 10, however I'll need it to work on Windows 7 as well.
I have file.zip which contains x zip files within it, each of which also contain x zip files. How would I be able to extract all of these "not manually"? I.E. with a bach file or a python script?

  • Seems to be close to superuser.com/q/421915/328618. Alas you do not mention if the unpacked content can name-collide with the files already present or not (unpacked stuff might need an extra directory to contain it) and what should happen with the unpacked zip files. – mvw Jan 13 '18 at 20:55
1

Below is a method I've used in the past for the same type of task that you describe which I pulled from one of my "bag of scripts". I used the free 7-Zip application for this task with 100% success.

Essentially this . . .

  • Uses the 7-Zip (7za) app to extract zip file(s) contents in one location to another
  • Then it does an xcopy of extracted ZIP files within the initial extracted files and copies those to a working directory
  • Then it deletes ZIP files from source, and extracts the other zip files from working directory and loops until complete

Note: The 7za executable file may either need to be copied to the /system32 folder or you may need to set the path it resides into the PATH environment variable.


Batch Script

You will need to set the source, destination, and working directory variable values accordingly for your environment and needs only and the rest should just work as expected.

@ECHO ON

SET sourcedir=C:\Test\Source
SET destdir=C:\Test\Dest
SET workdir=C:\Test\WorkTemp

:unzip
7za -Y e "%sourcedir%" -o"%destdir%" -r
DEL /Q /F "%workdir%\*zip
XCOPY /Y /F %destdir%\*.zip "%workdir%"
DEL /Q /F %destdir%\*.zip

DIR "%workdir%\*.zip" /A-D                         
IF ERRORLEVEL 1 GOTO :done

:unzip2
7za -Y e "%workdir%" -o"%destdir%" -r
DEL /Q /F "%workdir%\*.zip"
XCOPY /Y /F %destdir%\*.zip "%workdir%"
DEL /Q /F %destdir%\*.zip

DIR "%workdir%\*.zip" /A-D                         
IF ERRORLEVEL 1 GOTO :done
GOTO :unzip2

:done
GOTO :EOF

Further Resources

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.