I am trying to achieve one requirement that I have nested zip files there. I need to Unzip all those by single click. For that I have a code wich is working only for one zipped folder and need to expand this. below is the code which I need to expand:
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
Unzip "E:\Softwares\PS\AllFiles.zip" "E:\Softwares\PS\AllFiles"
Can any one suggest me a way to expand this to unzip the nested zip folders..
Your question isn't very detailed. I played with a little by having a file on C:\\temp\\ziptest that I placed multiple nested zip files in and this worked. Please note there could be a lot more variables that need to be accounted for (ie zip files have password, are they standard zip file or .7z, etc).
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
$flag = $true
while($flag)
{
$zipFiles = Get-ChildItem -Path "C:\temp\ziptest" -Recurse | Where-Object {$_.Name -like "*.zip"}
if($zipFiles.count -eq 0)
{
$flag = $false
}
elseif($zipFiles.count -gt 0)
{
foreach($zipFile in $zipFiles)
{
#create the new name without .zip
$newName = $zipFile.FullName.Replace(".zip", "")
Unzip $zipFile.FullName $newName
#remove zip file after unzipping so it doesn't repeat
Remove-Item $zipFile.FullName
}
}
Clear-Variable zipFiles
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.