是否有Windows命令行命令,我可以使用它来获得当前工作目录的完整路径?

另外,如何将此路径存储在批处理文件中使用的变量中?


当前回答

这对我来说一直都很有效:

SET CurrentDir="%~dp0"

ECHO The current file path this bat file is executing in is the following:

ECHO %CurrentDir%

Pause

其他回答

批处理/环境变量的设置方法如下:

SET var=%cd%
ECHO %var%

Windows 7 x64 cmd.exe的截图示例。

更新:如果你做一个SET var=%cd%而不是SET var=%cd%,下面是发生的事情。多亏了杰布。

从批处理文件捕获当前目录

对于Windows,我们可以使用

cd

和Linux

pwd

命令就在那里。

这对我来说一直都很有效:

SET CurrentDir="%~dp0"

ECHO The current file path this bat file is executing in is the following:

ECHO %CurrentDir%

Pause

在Windows上:

CHDIR显示当前目录名称或更改当前目录。

在Linux中:

PWD显示当前目录名称。