unzip file using 7z in powershell

喜夏-厌秋 提交于 2020-01-11 09:47:10

问题


What is the command to unzip a file using 7z in powershell?

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
sz x  $zipfilePath $destinationUnzipPath -aoa -r;

The command works fine but it says no files to process, everything is Ok rather than unzipping the file?


回答1:


This finally worked for me sz x -o$destinationUnzipPath $zipfilePath -r ;




回答2:


Aliases are not meant for that, they are meant to proxy other commands, not commands + parameters.

To achieve what you want you would need to use a functions:

function sz($args) {
    Start-Process "$env:ProgramFiles\7-Zip\7z.exe" -ArgumentList $args
}



回答3:


I didn't want to use aliases, functions or Start-Process. After a little looking around the web, I've found this gem (and I can't remember where):

& ${env:ProgramFiles}\7-Zip\7z.exe x $zipfilePath "-o$($destinationUnzipPath)" -y

And you can add a > $null at the end if you don't want to see 7z's messages!



来源:https://stackoverflow.com/questions/42998669/unzip-file-using-7z-in-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!