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

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


当前回答

对于Windows,我们可以使用

cd

和Linux

pwd

命令就在那里。

其他回答

对于Windows, cd本身会显示当前工作目录。

对于UNIX和类似工作的系统,pwd将执行相同的任务。您还可以在某些shell下使用$PWD shell变量。我不确定Windows是否支持通过shell变量获取当前工作目录。

在System32下创建一个。bat文件,命名为copypath.bat,复制当前路径的命令如下:

echo %cd% | clip

解释: %cd%将给出当前路径

CLIP

Description:
    Redirects output of command line tools to the Windows clipboard.
    This text output can then be pasted into other programs.

Parameter List:
    /?                  Displays this help message.

Examples:
    DIR | CLIP          Places a copy of the current directory
                        listing into the Windows clipboard.

    CLIP < README.TXT   Places a copy of the text from readme.txt
                        on to the Windows clipboard.

现在,任何地方都可以使用copypath。

对于Windows,我们可以使用

cd

和Linux

pwd

命令就在那里。

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

SET var=%cd%
ECHO %var%

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

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

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