如何仅为该批处理文件添加设置路径? [英] How to add a set path only for that batch file executing?

查看:50
本文介绍了如何仅为该批处理文件添加设置路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我知道我可以浏览控制面板并修改path变量.但是,我想知道是否有一种方法可以通过批处理编程包含一条临时路径?这样,它仅在批处理文件执行期间使用.我不想让人们为了使用我的批处理文件而修改其路径变量.

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 ,并查看该站点上的其他参考-

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屋!

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