Windows 中的命令 cd /d %~dp0 是什么意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18309941/
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
What does it mean by command cd /d %~dp0 in Windows
提问by Indranil Sarkar
Can someone please help me to understand the command cd /d %~dp0
and its purposes. Again dos command is below
有人可以帮助我理解命令cd /d %~dp0
及其目的。再次 dos 命令如下
cd /d %~dp0
Please help me to get the meaning of it.
请帮助我理解它的含义。
回答by wilx
Let's dissect it. There are three parts:
我们来剖析一下。分为三个部分:
cd
-- This is change directory command./d
-- This switch makescd
change both drive and directory at once. Without it you would have to docd %~d0 & cd %~p0
. (%~d0
Changs active drive,cd %~p0
change the directory).%~dp0
-- This can be dissected further into three parts:%0
-- This represents zeroth parameter of your batch script. It expands into the name of the batch file itself.%~0
-- The~
there strips double quotes ("
) around the expanded argument.%dp0
-- Thed
andp
there are modifiers of the expansion. Thed
forces addition of a drive letter and thep
adds full path.
cd
-- 这是更改目录命令。/d
-- 此开关可以同时cd
更改驱动器和目录。没有它,您将不得不这样做cd %~d0 & cd %~p0
。(更改%~d0
活动驱动器,cd %~p0
更改目录)。%~dp0
——这可以进一步分解为三个部分:%0
-- 这表示批处理脚本的第零个参数。它扩展为批处理文件本身的名称。%~0
--~
there"
在扩展参数周围去掉双引号 ( )。%dp0
--d
并且p
有扩展的修饰符。该d
部队另外一个驱动器号和p
补充完整路径。
回答by Stephan
~dp0
: d=drive, p=path, %0=full path\name of this batch-file.
~dp0
: d=drive, p=path, %0=这个批处理文件的完整路径\名称。
cd /d %~dp0
will change the path to the same, where the batch file resides.
cd /d %~dp0
会将路径更改为批处理文件所在的相同路径。
See for /?
or call /
for more details about the %~...
modifiers.
See cd /?
about the /d
switch.
有关修饰符的更多详细信息,请参阅for /?
或。
请参见有关开关。call /
%~...
cd /?
/d