I goofed up a setting on the backup software I use. Normally I would have the files from a network share get loaded into a spare drive, compressed into zip folders, then sent off to the offsite hub.

What instead happened was the compression happened first, so now I have a network share full of my original directories, but all the files have been compressed into their own zip folder.

Is there a fast way I could decompress all zip folders on the server where they are, then delete the ZIP files? I have 7-zip which seems like it might do the job.

What I've tried so far:

I've ran a search for and ZIP files, then selected "Extract Here" from the 7zip menu, but that extracts the ZIP files to whatever folder I happened to have right clicked on, instead of where they actually reside. I have file versioning turned on, but the latest backup I have is too far in the past.

  • Had any success using either of the script methods?
    – gm2
    Jul 25 '13 at 19:32

A quick and dirty powershell script to do what you need, you'll need 7zip commandline version. Just change the two paths in the sript and TEST it first, don't have the opportunity to do so myself at the moment.


Get-ChildItem $folderPath -recurse | %{ 

    if($_.Name -match "^*.`.zip$")
        $parent="$(Split-Path $_.FullName -Parent)";    
        write-host "Extracting $($_.FullName) to $parent"

        $arguments=@("e", "`"$($_.FullName)`"", "-o`"$($parent)`"");
        $ex = start-process -FilePath "`"C:\Path\To\7zip\7z.exe`"" -ArgumentList $arguments -wait -PassThru;

        if( $ex.ExitCode -eq 0)
            write-host "Extraction successful, deleting $($_.FullName)"
            rmdir -Path $_.FullName -Force
  • I tested this powershell script and it works for me. What's the specific text of the error message?
    – gm2
    Jul 18 '13 at 20:45
  • 2
    Yeah, simply change the first if-condition to: if(($_.Name -match "^*.`.zip$") -and ($_.Name -notmatch "nameToIgnore"))
    – Martin
    Sep 5 '13 at 18:02
  • 1
    using "x" instead of "e" under the arguments extracts preserving the directory structure of the zip file.
    – eminsenay
    Dec 12 '13 at 19:10
  • 1
    You can add "-NoNewWindow" to the start-process to prevent a new console window from popping up with each 7z command.
    – Eric Cosky
    Aug 16 '14 at 18:58
  • 1
    @Zulgrib the ` (backtick) is an escape character, and is used to the escape the .(dot) so that it is treated as a literal dot, and not as a special regex character. You can also see that it is used to escape double quotes (") when they appear in the middle of a string.
    – Martin
    Feb 23 at 22:59

This can be run on the command line:

for /r %f in (*.zip) do 7z x "%f" -o"%~pf" && del "%f"

Details of for /r: https://ss64.com/nt/for_r.html

The %~pf is expanded to the path (as stated in 'for' command help: for /?).

  • Thanks! Worked perfectly.
    – masroore
    Aug 12 at 14:43

This version resolves all issues with spaces and puts files into source directory of each archive:

set folderPath="N:\Private
for /f "usebackq delims=|" %%f in (`dir /s /b %folderPath%\*.zip"`) do "C:\Program Files\7-Zip\7z.exe" x "%%f" -aoa -o"%%~dpf" && del "%%f"

The following can be run from Windows command line. Modify the path to 7-Zip executable as necessary.
set folderPath="X:\Test"
for /f %f in ('dir /s /b %folderPath%\*.zip') do "C:\Program Files\7-Zip\7z.exe" x %f -o%folderPath%\* && del /p %f

Remove the /p if you do not want to be prompted to delete each zip file.

  • I get error "set folderPath="C:/test" do was unexpected at this time."
    – user201262
    Jul 18 '13 at 21:09
  • Please try it again. I've fixed an issue in the command where the backslash immediately following each instance of %folderPath% wasn't being rendered in the code block. I forgot that backslash is an escape character in markdown syntax.
    – gm2
    Jul 18 '13 at 21:31
  • "x folderPathf was unexpected at this time"
    – user201262
    Jul 24 '13 at 19:41
  • Are you running this in a batch file? If so you need to replace all %f with %%f. Don't change %folderPath%
    – gm2
    Jul 24 '13 at 20:31

use Winrar instead of 7ZIP, and then select all your zip files, and right click, select Extract each archive to separate folder

this will extract each zip into their respective folder, then delete all ZIP's

  • WinRAR's Extract each archive to separate folder produces same output as 7-Zip's Extract to "\*" when multiple zip files are selected. Does not decompress all zip files in-place as @moses wants.
    – gm2
    Jul 25 '13 at 16:32
  • I don't want each archive to be extracted to its own folder. Like I said in the question, I want them extracted into the folders where they currently reside.
    – user201262
    Jul 25 '13 at 19:33
  • @gm2: this has not been my experience with 7-zip. What you described is exactly what you'd expect it to do, but it always dumps everything into a folder named [0]~' for me. Irritating. Apr 2 '14 at 23:53

Your Answer

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