在 powershell 中使用 7z 解压文件

unzip file using 7z in powershell

在 powershell 中使用 7z 解压缩文件的命令是什么?

set-alias sz "$env:ProgramFiles-Zipz.exe"
sz x  $zipfilePath $destinationUnzipPath -aoa -r;

命令运行正常,但它说没有要处理的文件,一切正常而不是解压缩文件?

这终于对我有用sz x -o$destinationUnzipPath $zipfilePath -r ;

我不想使用别名、函数或 Start-Process。稍微浏览了一下网络后,我发现了这个 gem(我不记得在哪里):

& ${env:ProgramFiles}-Zipz.exe x $zipfilePath "-o$($destinationUnzipPath)" -y

如果不想看到7z的消息可以在末尾加一个> $null

使用 7zip PowerShell 模块,现在无忧无虑

#   Install 7zip module

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name 'PSGallery' -SourceLocation "https://www.powershellgallery.com/api/v2" -InstallationPolicy Trusted
Install-Module -Name 7Zip4PowerShell -Force

#   Extract 7zip file

$sourcefile = "c:\source\sample.7z"
Expand-7Zip -ArchiveFileName $sourcefile -TargetPath 'c:\destinaation'

我使用了"fullname",其中包括路径。
此外,我必须将 PowerShell 中的目录更改为提取数据的输出目录,即 D:\temp

我不相信将大量文件从不同的文件夹复制或提取到一个位置在这个时代是一项复杂的任务。

$rars = (Get-ChildItem "D:\Path\To\folder" -Recurse *.rar).fullname
foreach ($rar in $rars) {& "C:\Program Files-Zipz.exe" e $rar}