Hi,
I’m trying to write a script to unzip multiple zip files to multiple folders. Essentially I want to be able type in the source and destination folders that contain 10s or 100s of zip files and have it create the folders and start unzipping each zip file to the folder with the same name.
I originally tried doing this with loops and the Expand-Archive cmdlet but I ran in to some problems and now I’m trying with the .Net framework class for file compression.
I’ve been able to put together the below code which kind of works but it added all the folder names in the destination path together to make the new folder to move the extracted files. Right now I’m kind of stuck for ideas about how I can fix this and extract to all separate folders, like in the example of bash code below the powershell script.
Your help with this is much appreciated!
$src = "C:\Temp\zip\"
$dest = "C:\Temp\unzip\"
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zps = Get-ChildItem $src -Filter *.zip
$foldernames = Get-ChildItem $dest
$newfolders = $dest + $foldernames
foreach ($zp IN $zps)
{
$all = $src + $zp
[System.IO.Compression.ZipFile]::ExtractToDirectory($all, $newfolders)
}
A Linux world example of what I want to achieve:
find -name '.zip' -exec sh -c 'unzip -d "${1%.}" "$1"' _ {} \;