提取-归档到传统文件夹结构

Extract-Archive to traditional folder structure

当尝试以传统方式在 Windows 中解压缩文件时,它会将 zip 文件的名称解压缩为文件夹,并将文件嵌入文件夹本身。我无法使用 Extract-Archive Cmdlet 重新创建它。这是我的代码部分: Get-ChildItem 'path of zip' -Filter *.zip | Expand-Archive -DestinationPath 'path to extract' -Force 虽然 运行 这个,解压缩过程工作正常。我只是想知道在使用 Expand-Archive Cmdlet

时是否有办法保留传统的 unzip file/folder 结构

谢谢

您可以在参数DestinationPath中设置目标文件夹。如果与 zip 文件同名的文件夹尚不存在,将创建它:

$sourcePath  = 'path of zip file(s)'
$destination = 'path to extract'

Get-ChildItem -Path $sourcePath -Filter '*.zip' -File | ForEach-Object {
    $target = Join-Path -Path $destination -ChildPath $_.BaseName
    $_ | Expand-Archive -DestinationPath $target -Force
}