在 powershell 中使用 7z 解压缩文件的命令是什么?
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
sz x $zipfilePath $destinationUnzipPath -aoa -r;
该命令工作正常,但它说没有文件要处理,一切都好,而不是解压缩文件?
这终于为我工作了sz x -o$destinationUnzipPath $zipfilePath -r ;
我不想使用别名,函数或Start-Process
。在网上看了一下之后,我发现了这个宝石(我不记得在哪里):
& ${env:ProgramFiles}\7-Zip\7z.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'
我的用例略有不同,因为我在一个需要提取的目录中有多个 tar 文件。我正在共享它,因为也可以使用相同的命令或稍微修改以使用:
这是通过 Powershell 在 Windows 10 上为我工作的命令:
注意:当然,您需要为您的用例更改以下路径。
$srcFolderPathWithTar="C:\SomeFilder\has\multiple\tar\files"
$targ="C:\Users\your_user_name\Downloads\new"
. "C:\Program Files\7-Zip\7z.exe" x "-o$($targ)" "$srcFolderPathWithTar" -r -y;
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(65条)