8

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.

5 Answers5

5

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
        }
    }
}
Martin
  • 1,327
3

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 /?).

0

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"
Rualark
  • 131
-1

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.

gm2
  • 796
-1

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