Windows shell command to get the full path to the current directory?

前端 未结 14 1601
一向
一向 2020-11-30 17:51

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

相关标签:
14条回答
  • 2020-11-30 18:16

    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.

    0 讨论(0)
  • 2020-11-30 18:18

    For Windows we can use

    cd

    and for Linux

    pwd

    command is there.

    0 讨论(0)
  • 2020-11-30 18:22

    As one of the possible codes

        echo off
        for /f "usebackq tokens=* delims= " %%x in (`chdir`) do set var=%var% %%x
        echo The current directory is: "%var:~1%"
    
    0 讨论(0)
  • 2020-11-30 18:24

    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).

    0 讨论(0)
  • 2020-11-30 18:24
    @echo off
    for /f "usebackq tokens=*" %%x in (`chdir`) do set var=%%x
    echo The currenct directory is: %var%
    

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

    0 讨论(0)
  • 2020-11-30 18:25

    On Windows, type cd for the working current path.

    On Linux, pwd for the current working path.

    0 讨论(0)
提交回复
热议问题