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:08

For Windows, cd by itself will show you the current working directory.

For UNIX and workalike systems, pwd will perform the same task. You can also use the $PWD shell variable under some shells. I am not sure if Windows supports getting the current working directory via a shell variable or not.

查看更多
混吃等死
3楼-- · 2019-01-16 05:09

For Windows we can use

cd

and for Linux

pwd

command is there.

查看更多
Juvenile、少年°
4楼-- · 2019-01-16 05:12

Based on the follow up question (store the data in a variable) in the comments to the chdir post I'm betting he wants to store the current path to restore it after changeing directories.

The original user should look at "pushd", which changes directory and pushes the current one onto a stack that can be restored with a "popd". On any modern Windows cmd shell that is the way to go when making batch files.

If you really need to grab the current path then modern cmd shells also have a %CD% variable that you can easily stuff away in another variable for reference.

查看更多
Rolldiameter
5楼-- · 2019-01-16 05:12

Create a .bat file under System32, let us name it copypath.bat the command to copy current path could be:

echo %cd% | clip

Explanation:

%cd% will give you current path

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.

Now copyclip is available from everywhere.

查看更多
我命由我不由天
6楼-- · 2019-01-16 05:13

On Windows:

CHDIR Displays the name of or changes the current directory.

In Linux:

PWD Displays the name of current directory.

查看更多
放我归山
7楼-- · 2019-01-16 05:13

In a Windows command prompt, chdir or cd will print the full path of the current working directory in the console.

If we want to copy the path then we can use: cd | clip.

查看更多
登录 后发表回答