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 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.

share|improve this question
    
Had any success using either of the script methods? –  gm2 Jul 25 '13 at 19:32

3 Answers 3

up vote 4 down vote accepted

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.

$folderPath="X:\Test";

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
        }
    }
}
share|improve this answer
    
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
    
This ended up working for me, sorry about the lateness. Is there any way I could instruct 7zip in this script to ignore a particular .zip filename in the group? –  Moses Sep 4 '13 at 17:58
1  
Yeah, simply change the first if-condition to: if(($_.Name -match "^*.`.zip$") -and ($_.Name -notmatch "nameToIgnore")) –  Martin Sep 5 '13 at 18:02
    
using "x" instead of "e" under the arguments extracts preserving the directory structure of the zip file. –  eminsenay Dec 12 '13 at 19:10
    
Awesome! PS FTW –  Dennis G Jul 8 at 18:13

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.

share|improve this answer
    
I get error "set folderPath="C:/test" do was unexpected at this time." –  Moses 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" –  Moses 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

share|improve this answer
    
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. –  Moses 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. –  Nucking Futz Apr 2 at 23:53

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.