Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a large Windows 7 folder tree structure containing many zip files. These are single layer zip files (not zip within zip). What 7-zip command can I use to parse through this folder structure, find each the zip file by file extension (see example), extract it (deleting the zip file, leaving the extracted files) to the same location?

Example: All of the files in the hierarchy of folders are named something like: abc.mp3.zip or xyz.jpg.zip - the native file extension followed by ".zip". I want 7-zip to find all files in the tree by file extension using wildcards (*.mp3.zip, *.jpg.zip, etc) and extract these to the current location without creating new folders so that the result is abc.mp3 and xyz.jpg. Thanks.

share|improve this question
3  
There is no 7-zip "command" for something that intricate, you'll want to write a script. –  John T Feb 2 '11 at 15:57

1 Answer 1

As far as I can tell, 7-zip doesn't have a command that does what you're looking for. Here's a Windows batch file script which I think will do what you want. It should be run from the command line so you can supply a path to the root of the folder tree to be processed.

File unzipper.bat

@echo off
setlocal
if "%1"=="" goto Usage

call :Get7zCmd
:: Recurse folder passed in as paramater
for /r %1 %%Z in (*.zip) do (
    echo ====
    rem Change to the directory of zip file
    cd /d "%%~dpZ"
    rem Extract all files to current directory
    echo %_7zCmd% e "%%~nxZ" -y
    rem Delete the zip file
    echo del "%%~nxZ"
)
goto End

:Usage
echo.
echo Parses through folder structure starting at the specified path, finding
echo and extracting the contents of all zip files found, and then deletes
echo the zip file.
echo.
echo Usage:
echo     %~n0 root-directory-path
echo.
echo     For example:
echo.
echo %~n0 "D:\some folder"

:End
goto :EOF

:: ==========================
:: Subroutine Get7zCmd
:: Determines the full path to 7-zip command-line executable from the Windows
:: Registry and sets the variable "_7zCmd" to the result.
:Get7zCmd
set Reg.Key=HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe
set Reg.Val=Path
for /F "Tokens=2*" %%A in ('Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| find /I "%Reg.Val%"') do call set PathDirectory=%%B
set _7zCmd="%PathDirectory%%\7z.exe"
exit /b 0

Since as a whole what the script does is fairly radical and potentially destructive since might extract large numbers of file and delete many zip files afterward. I've disabled the commands on lines 12 and 14 which would do those steps by prefixing them with echo. This make them just print out what they would have done if the echo wasn't there. That way you can test the script first without doing any damage to your file system should there be some sort of unexpected problem.

To make the script actually perform these actions, you'll need to remove the echo on each of the two lines. Standard disclaimer of any liability applies, of course.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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