windows 如何更改目录以从不同驱动器运行 .bat 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22481298/
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
How to change directory to run .bat files from different drive?
提问by Borealis
I have some .bat files that I run from the local directory (e.g. C:\Users\pozna001). However, when I try and change the directory to a data drive using cd F:\nrcs_project
to run the .bat files from a different location, I see that the command prompt does not recognize the cd
command. How can I change the directory in the command prompt so that I can run these .bat files from a different drive (i.e. a data drive connected to a server)?
我有一些从本地目录(例如 C:\Users\pozna001)运行的 .bat 文件。但是,当我尝试将目录更改为用于cd F:\nrcs_project
从不同位置运行 .bat 文件的数据驱动器时,我看到命令提示符无法识别该cd
命令。如何更改命令提示符中的目录,以便可以从不同的驱动器(即连接到服务器的数据驱动器)运行这些 .bat 文件?
回答by giammin
CD /D F:\nrcs_project
Use the /D
switch to change current drive in addition to changing current directory for a drive.
/D
除了更改驱动器的当前目录外,还可以使用开关更改当前驱动器。
回答by nostriel
Both solution above are correct.
以上两种解决方案都是正确的。
The fastest is:
最快的是:
cd /d f:\nrcs_project
cd /df:\nrcs_project
But you could change drive first, then the directory.
但是您可以先更改驱动器,然后再更改目录。
Use cd /? and it will show you all params.
使用 cd /? 它会显示所有参数。
回答by Yggdrasil_
If you need to go from a device to another (in your case from C:\
to F:\
, you need to type F:
before/after you entered your cd
command, so it will go on the F
device. Otherwise, you can use the /D
parameter of the cd
function.
如果您需要从一个设备转到另一个设备(在您的情况下从C:\
to F:\
,您需要F:
在输入cd
命令之前/之后键入,因此它会在F
设备上运行。否则,您可以使用/D
该cd
函数的参数。
So to sum up,
所以总结一下,
$C:\Folder> F:
$F:\>cd F:\whatever
$F:\whatever>...
or
或者
$C:\Folder> cd F:\whatever
$C:\Folder> F:
$F:\whatever>...
or
或者
$C:\Folder> cd /D F:\whatever
$F:\whatever>...
回答by Johnny Bones
You first need to type F:to change to the F:\ drive, then you can use the CD command
首先需要输入F:切换到 F:\ 驱动器,然后可以使用 CD 命令
Or you can use the /D switch to do it all in one shot:
或者您可以使用 /D 开关一次性完成所有操作:
CD /D F:\nrcs_project
回答by Yaugen Vlasau
the command will look like following:
该命令将如下所示:
F: && cd nrcs_project