unzip files from folders and subfolders

February 5, 2011 at 05:33:42
Specs: Windows XP
Restoring from Cobian backup. Copied all folders back to replaced hard drive.

Now I have a set of folders and subfolders all containing zip files that need extraction. Will need to delete the zip files at the end.

The script can unzip all files first from folders and subfolders and then delete all zip files as a second step. The other option would be to get each zip, extract it and then delete the zip file in one loop.

I am using 7zip on windows xp and the file system is NTFS

Any suggestions?


See More: unzip files from folders and subfolders

Report •

February 5, 2011 at 10:29:06
7zip has a command line version called 7za.exe that can be downloaded from 7zip.org

The command I need to use for any file is:

7za x archive.zip -oC:\Doc

7z: executable name
x: extract archive with paths intact
archive.zip: archive to extract files from
-oC:\Doc: extract all files to the Doc folder on the C: drive

If the -o switch is omitted, the files are extracted to the parent directory

Path "{7za folder}"
CD "D:\MyFiles\My Documents\folder"
for /r "D:\MyFiles\My Documents\folder" %%X in (*.zip) do (7za x "%%X")
del *.zip /s

Should work well for me except that I want the files to extract the relevant folders, not the parent folder. Anybody??


Report •

February 5, 2011 at 11:34:44
@echo off
rem The first loop does the work on the parent directory
for /f "tokens=*" %%b in ('dir/b *.zip') do (
7za x "%%b"

rem This double loop works on subfolders
for /f "tokens=*" %%c in ('dir/b/s/ad') do (
CD "%%c"
for /f "tokens=*" %%d in ('dir/b *.zip') do (
7za x "%%d"
del *.zip/s

Hope this is useful. If anybody has any suggestions for a tidier code, please submit.


Report •

Related Solutions

Ask Question