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

前端 未结 14 1603
一向
一向 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:26

    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.

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

    On Unix?

    pwd

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

    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.

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

    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
    
    0 讨论(0)
  • 2020-11-30 18:32

    On Windows:

    CHDIR Displays the name of or changes the current directory.

    In Linux:

    PWD Displays the name of current directory.

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

    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.

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