Windows shell command to get the full path to the

2019-01-16 05:00发布

Is there a Windows command line command that I can use to get the full path to the current working directory?

Also, how can I store this path inside a variable used in a batch file?

13条回答
祖国的老花朵
2楼-- · 2019-01-16 05:17

Use cd with no arguments if you're using the shell directly, or %cd% if you want to use it in a batch file (it behaves like an environment variable).

查看更多
We Are One
3楼-- · 2019-01-16 05:17

On Unix?

pwd

查看更多
Explosion°爆炸
4楼-- · 2019-01-16 05:18

This has always worked for me:

SET CurrentDir="%~dp0"

ECHO The current file path this bat file is executing in is the following:

ECHO %CurrentDir%

Pause
查看更多
forever°为你锁心
5楼-- · 2019-01-16 05:19

Quote the Windows help for the set command (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.

Note the %CD% - expands to the current directory string. part.

查看更多
何必那么认真
6楼-- · 2019-01-16 05:22

On Windows, type cd for the working current path.

On Linux, pwd for the current working path.

查看更多
何必那么认真
7楼-- · 2019-01-16 05:25
@for /f "usebackq" %%x in (`chdir`) do set var=%%x
@echo "The currenct directory is: %var%"

But, of course, gmaran23's answer is the much easier one.

查看更多
登录 后发表回答