是否有Windows命令行命令,我可以使用它来获得当前工作目录的完整路径?
另外,如何将此路径存储在批处理文件中使用的变量中?
是否有Windows命令行命令,我可以使用它来获得当前工作目录的完整路径?
另外,如何将此路径存储在批处理文件中使用的变量中?
当前回答
引用Windows帮助中的set命令(set /?):
If Command Extensions are enabled, then there are several dynamic environment variables that can be expanded but which don't show up in the list of variables displayed by SET. These variable values are computed dynamically each time the value of the variable is expanded. If the user explicitly defines a variable with one of these names, then that definition will override the dynamic one described below: %CD% - expands to the current directory string. %DATE% - expands to current date using same format as DATE command. %TIME% - expands to current time using same format as TIME command. %RANDOM% - expands to a random decimal number between 0 and 32767. %ERRORLEVEL% - expands to the current ERRORLEVEL value %CMDEXTVERSION% - expands to the current Command Processor Extensions version number. %CMDCMDLINE% - expands to the original command line that invoked the Command Processor.
注意%CD% -扩展到当前目录字符串。部分。
其他回答
在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。
@echo off
for /f "usebackq tokens=*" %%x in (`chdir`) do set var=%%x
echo The currenct directory is: %var%
当然,gmaran23的答案要简单得多。
这对我来说一直都很有效:
SET CurrentDir="%~dp0"
ECHO The current file path this bat file is executing in is the following:
ECHO %CurrentDir%
Pause
如果您直接使用shell,则使用不带参数的cd,如果您希望在批处理文件中使用它,则使用%cd%(它的行为类似于环境变量)。
引用Windows帮助中的set命令(set /?):
If Command Extensions are enabled, then there are several dynamic environment variables that can be expanded but which don't show up in the list of variables displayed by SET. These variable values are computed dynamically each time the value of the variable is expanded. If the user explicitly defines a variable with one of these names, then that definition will override the dynamic one described below: %CD% - expands to the current directory string. %DATE% - expands to current date using same format as DATE command. %TIME% - expands to current time using same format as TIME command. %RANDOM% - expands to a random decimal number between 0 and 32767. %ERRORLEVEL% - expands to the current ERRORLEVEL value %CMDEXTVERSION% - expands to the current Command Processor Extensions version number. %CMDCMDLINE% - expands to the original command line that invoked the Command Processor.
注意%CD% -扩展到当前目录字符串。部分。