windows 更改批处理文件 (.bat) 的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3332576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:54:25  来源:igfitidea点击:

Changing the path of a batch file (.bat)

windowsbatch-file

提问by dapper

How can we change the path of a batch file (.bat) ?

我们如何更改批处理文件 (.bat) 的路径?

回答by mauris

I've got a feeling it is about changing the current working directory.

我有一种感觉是关于更改当前工作目录。

To do that, use the command cdto change current working directory.

为此,请使用命令cd更改当前工作目录。

@echo off
C:
cd C:\Windows\System32\

If you change both the current drive andthe current directory you'll need the /Dswitch:

如果您同时更改当前驱动器当前目录,则需要/D切换:

cd /D D:\Foo

回答by user1893459

as in adding a temporary extra path to %PATH%?

就像在 %PATH% 中添加临时额外路径一样?

try: set path=%PATH%;c:\folder

尝试:设置路径=%PATH%;c:\folder

where c:\folder is what you want to add

其中 c:\folder 是您要添加的内容

if you want a permanent path set use a tool called "setx"

如果您想要永久路径集,请使用名为“setx”的工具

otherwise you could call something directly without using CD etc using something like "c:\folder\program.exe"

否则你可以直接调用一些东西而不使用 CD 等使用类似“c:\folder\program.exe”的东西

回答by fedmich

Firstly, make sure you change the drivename to. then use cd command

首先,确保将驱动器名称更改为。然后使用 cd 命令

c:
cd "c:\windows\"

回答by Andreas

cd /d d:\foo

or, if you want to jump back to the source directory

或者,如果你想跳回源目录

pushd d:\foo

with

popd

you switch back to the directory before the pushd

你切换回 pushd 之前的目录

回答by griegs

Are you talking about changing the path of a command within the batch file? If yes then pass the path as an argument.

您是在谈论更改批处理文件中命令的路径吗?如果是,则将路径作为参数传递。

Hope I understood your question.

希望我理解你的问题。