【问题标题】:Extract-Archive to traditional folder structure提取存档到传统文件夹结构
【发布时间】:2021-04-11 09:02:36
【问题描述】:

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

谢谢

【问题讨论】:

  • 这个问题更适合在 superuser.com 中提问

标签: powershell unzip


【解决方案1】:

您可以在参数DestinationPath 中设置目标文件夹。如果该 zipfile 名称的文件夹尚不存在,则会创建该文件夹:

$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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    相关资源
    最近更新 更多