我想从“ c:\ Myfolder”中包含的一组嵌套.zip文件中提取扩展名为“ .wav”的文件。
This code说明了如何从.zip中提取.wav文件。我想最好先将所有zip文件解压缩到一个文件夹,然后再尝试以下代码。
#requires -Version 5.0
# change $Path to a ZIP file that exists on your system!
$Path = "$Home\Desktop\Test.zip"
# change extension filter to a file extension that exists
# inside your ZIP file
$Filter = '*.zip' # first extract the zip files
# change output path to a folder where you want the extracted
# files to appear
$OutPath = 'C:\ZIPFiles'
# ensure the output folder exists
$exists = Test-Path -Path $OutPath
if ($exists -eq $false)
{
$null = New-Item -Path $OutPath -ItemType Directory -Force
}
# load ZIP methods
Add-Type -AssemblyName System.IO.Compression.FileSystem
# open ZIP archive for reading
$zip = [System.IO.Compression.ZipFile]::OpenRead($Path)
# find all files in ZIP that match the filter (i.e. file extension)
$zip.Entries |
Where-Object { $_.FullName -like $Filter } |
ForEach-Object {
# extract the selected items from the ZIP archive
# and copy them to the out folder
$FileName = $_.Name
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$OutPath\$FileName", $true)
}
# close ZIP file
$zip.Dispose()
# open out folder
explorer $OutPath