是否有Windows命令行命令,我可以使用它来获得当前工作目录的完整路径?
另外,如何将此路径存储在批处理文件中使用的变量中?
是否有Windows命令行命令,我可以使用它来获得当前工作目录的完整路径?
另外,如何将此路径存储在批处理文件中使用的变量中?
当前回答
对于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。
作为可能的密码之一
echo off
for /f "usebackq tokens=* delims= " %%x in (`chdir`) do set var=%var% %%x
echo The current directory is: "%var:~1%"
@echo off
for /f "usebackq tokens=*" %%x in (`chdir`) do set var=%%x
echo The currenct directory is: %var%
当然,gmaran23的答案要简单得多。
批处理/环境变量的设置方法如下:
SET var=%cd%
ECHO %var%
Windows 7 x64 cmd.exe的截图示例。
更新:如果你做一个SET var=%cd%而不是SET var=%cd%,下面是发生的事情。多亏了杰布。
从批处理文件捕获当前目录
在Windows上:
CHDIR显示当前目录名称或更改当前目录。
在Linux中:
PWD显示当前目录名称。