如何解压多个 zip 文件夹

How to unzip multiple zip folders

我正在努力实现一个要求,即我在其中嵌套了 zip 文件。我需要通过单击解压缩所有这些。为此,我有一个代码只适用于一个压缩文件夹,需要扩展它。下面是我需要扩展的代码:

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"

任何人都可以建议我一种方法来扩展它以解压缩嵌套的 zip 文件夹..

你的问题不是很详细。我通过在 C:\temp\ziptest 上放置了多个嵌套的 zip 文件来玩了一点,这很有效。请注意,可能需要考虑更多变量(即 zip 文件有密码,它们是标准 zip 文件还是 .7z 等)。

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
}