Windows 7 – Recursively Unzip Files and Delete Archives

7-zipcompressionwindows 7zip

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.

Best Answer

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
        }
    }
}
Related Question