如何在Powershell和7zip中正确设置路径? [英] How to properly set path in Powershell and 7zip?

查看:333
本文介绍了如何在Powershell和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:ProgramFiles\7-Zip\7z.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆