是否有Windows命令行命令,我可以使用它来获得当前工作目录的完整路径?
另外,如何将此路径存储在批处理文件中使用的变量中?
是否有Windows命令行命令,我可以使用它来获得当前工作目录的完整路径?
另外,如何将此路径存储在批处理文件中使用的变量中?
当前回答
在Windows命令提示符中,chdir或cd将打印控制台中当前工作目录的完整路径。
如果我们想复制路径,那么我们可以使用:cd | clip。
其他回答
如果您直接使用shell,则使用不带参数的cd,如果您希望在批处理文件中使用它,则使用%cd%(它的行为类似于环境变量)。
在Windows下,输入cd作为当前工作路径。
在Linux操作系统中,pwd为当前工作路径。
@echo off
for /f "usebackq tokens=*" %%x in (`chdir`) do set var=%%x
echo The currenct directory is: %var%
当然,gmaran23的答案要简单得多。
在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。
在Unix ?
pwd