如何仅为该批处理文件执行添加设置路径? [英] How to add a set path only for that batch file executing?
问题描述
基本上,我知道我可以通过我的控制面板修改路径变量.但是,我想知道是否有办法通过批处理编程包含一个临时路径?这样它只在批处理文件执行期间使用.我不想让人们进入并修改他们的路径变量只是为了使用我的批处理文件.
Basically, I know I can go through my control panel and modify the path variable. But, I'm wondering if there is a way to through batch programming have a temporary path included? That way it is only used during that batch file execution. I don't want to have people go in and modify their path variables just to use my batch file.
推荐答案
就像任何其他环境变量一样,使用 SET
:
Just like any other environment variable, with SET
:
SET PATH=%PATH%;c:whateverelse
如果你想先内置一点安全检查,请先检查新路径是否存在:
If you want to have a little safety check built in first, check to see if the new path exists first:
IF EXIST c:whateverelse SET PATH=%PATH%;c:whateverelse
如果您希望该批处理文件是本地的,请使用 setlocal
:
If you want that to be local to that batch file, use setlocal
:
setlocal
set PATH=...
set OTHERTHING=...
@REM Rest of your script
仔细阅读 setlocal
/endlocal
的文档,并查看该站点上的其他参考资料 - Functions 也很有趣,语法也很复杂.
Read the docs carefully for setlocal
/endlocal
, and have a look at the other references on that site - Functions is pretty interesting too and the syntax is tricky.
语法页面应该让您从基础开始.
The Syntax page should get you started with the basics.
这篇关于如何仅为该批处理文件执行添加设置路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!