PowerShell script to recursively recompress ZIP-files with higher compression. Note that Deflate64 isn’t strictly zip standard afaik, but it works for most zip applications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Remove-Item temp -Recurse -Force -Confirm:$false -ErrorAction Ignore $totalSaved=0 $fileCount=0 foreach ($file in $(gci -Recurse *.zip)) { $fileCount++ $before=$file.Length mkdir temp echo $file.FullName cd temp Write-Host "Extract $($file.Name)" -ForegroundColor Green & "C:\Program Files\7-Zip\7z.exe" x "$($file.FullName)" -y Write-Host "Compress $($file.Name)" -ForegroundColor Green Remove-Item $file -Recurse -Force -Confirm:$false & "C:\Program Files\7-Zip\7z.exe" a "$($file.FullName)" -y -tzip -sdel -slp -aoa -mx=9 -mm=Deflate64 -mfb=257 -mmt=on -mpass=15 cd .. Remove-Item temp -Recurse -Force -Confirm:$false $after=(gci $file).Length $totalSaved += $before - $after Write-Host "$($file.Name) bytes saved: $($before - $after)." -ForegroundColor Yellow Write-Host "Total bytes saved by recompressing $($fileCount) files: $($totalSaved)" -ForegroundColor Yellow } |