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

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


当前回答

作为可能的密码之一

    echo off
    for /f "usebackq tokens=* delims= " %%x in (`chdir`) do set var=%var% %%x
    echo The current directory is: "%var:~1%"

其他回答

在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命令提示符中,chdir或cd将打印控制台中当前工作目录的完整路径。

如果我们想复制路径,那么我们可以使用:cd | clip。

如果您直接使用shell,则使用不带参数的cd,如果您希望在批处理文件中使用它,则使用%cd%(它的行为类似于环境变量)。

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

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%,下面是发生的事情。多亏了杰布。

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