命令提示符 - 如何添加一组路径仅用于执行批处理文件? [英] Command Prompt - 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:\whatever\else
如果你想拥有内置的第一个一点点的安全检查,检查是否新路径存在第一:
If you want to have a little safety check built in first, check to see if the new path exists first:
IF EXIST c:\whatever\else SET PATH=%PATH%;c:\whatever\else
如果你想,要成为本地该批处理文件,使用 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
读取文档,并看看在该网站上的其他参考 - 功能是pretty有趣也和语法是棘手的。
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屋!