如何在 Powershell 和 7zip 中正确设置路径? [英] How to properly set path in Powershell and 7zip?
问题描述
我有一个 Powershell 脚本,可以通过 7zip 创建一个自解压存档.但它收到此错误:
I have a Powershell script to create a self-extracting archive via 7zip. But it's receiving this error:
找不到指定的 SFX 模块
cannot find specified SFX module
Powershell 代码是:
The Powershell code is:
set-alias sz "$env:ProgramFiles7-Zip7z.exe
sz a -t7z -sfx -ppassword $fullpath $filetostore
两个变量都是有效的.我试过 -sfx
和 -sfx7z.sfx
,同样的错误.7z.sfx 文件确实与 7zip 位于正确的文件夹中.我还可以验证别名是否有效,因为在运行代码时会出现 7zip 版权(因此正在启动 7zip 命令行).此命令在 Powershell 之外工作.
Both variables are valid. I've tried -sfx
and -sfx7z.sfx
, same error. The 7z.sfx file is indeed in the correct folder with 7zip. I can also verify the alias is working, as the 7zip copyright appears when running the code (so 7zip commandline is being initiated). This command works outside Powershell.
我也试过 Set-Location
进入 7zip 文件夹,但同样的错误.我错过了什么?
I'm also tried Set-Location
into the 7zip folder, but same error. What am I missing?
推荐答案
看来您应该将 7-zip 文件夹添加到您的 PATH
环境变量中以简化操作:
It seems you should add the 7-zip folder to your PATH
environment variable to make things easier :
#find the 7-zip folder path
$7zPath = (Get-ChildItem "C:Program Files","C:Program Files (x86)" -Include "7-zip" -Recurse -ErrorAction SilentlyContinue).FullName
#add it to PATH environment variable
$env:Path += ";$7zPath;"
然后您可以运行 7z -sfx
而不会出现关于 SFX
模块的错误.
Then you can run 7z -sfx
with no errors about the SFX
module.
这篇关于如何在 Powershell 和 7zip 中正确设置路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!