Which command should you use to display the current path of your current directory?

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?

Which command should you use to display the current path of your current directory?

asked Mar 3, 2009 at 19:03

2

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

Which command should you use to display the current path of your current directory?

answered Mar 3, 2009 at 19:05

Trevor BrambleTrevor Bramble

8,1533 gold badges29 silver badges28 bronze badges

4

You can set a batch/environment variable as follows:

SET var=%cd%
ECHO %var%

sample screenshot from a Windows 7 x64 cmd.exe.

Which command should you use to display the current path of your current directory?

Update: if you do a SET var = %cd% instead of SET var=%cd% , below is what happens. Thanks to jeb.

Which command should you use to display the current path of your current directory?

Capturing the current directory from a batch file

answered Jul 4, 2013 at 8:13

gmaran23gmaran23

2,0482 gold badges17 silver badges18 bronze badges

3

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.

answered Mar 4, 2009 at 11:55

Patrick CuffPatrick Cuff

27.8k11 gold badges67 silver badges94 bronze badges

answered Mar 3, 2009 at 19:06

1

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

Which command should you use to display the current path of your current directory?

Danny Beckett

19.9k23 gold badges105 silver badges134 bronze badges

answered Mar 3, 2013 at 0:29

Which command should you use to display the current path of your current directory?

Fred ScalesFred Scales

3073 silver badges2 bronze badges

3

For Windows we can use

cd

and for Linux

pwd

command is there.

answered Oct 1, 2013 at 13:46

Which command should you use to display the current path of your current directory?

Nikunj K.Nikunj K.

8,3294 gold badges42 silver badges52 bronze badges

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 copypath is available from everywhere.

answered Sep 12, 2018 at 18:57

Which command should you use to display the current path of your current directory?

VishrantVishrant

14.1k11 gold badges66 silver badges104 bronze badges

1

On Windows:

CHDIR Displays the name of or changes the current directory.

In Linux:

PWD Displays the name of current directory.

Which command should you use to display the current path of your current directory?

answered Aug 17, 2015 at 17:01

Which command should you use to display the current path of your current directory?

Ajay JayavarapuAjay Jayavarapu

4611 gold badge6 silver badges16 bronze badges

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.

answered Mar 3, 2009 at 19:10

Michael TrauschMichael Trausch

3,1871 gold badge21 silver badges29 bronze badges

2

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.

answered Mar 3, 2009 at 19:23

MarkMark

1,0586 silver badges13 bronze badges

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.

Which command should you use to display the current path of your current directory?

answered Jan 30, 2016 at 10:09

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

answered Jul 4, 2013 at 8:30

Which command should you use to display the current path of your current directory?

René NyffeneggerRené Nyffenegger

38.5k32 gold badges155 silver badges275 bronze badges

2

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%"

answered May 24, 2020 at 10:12

GarricGarric

5413 silver badges9 bronze badges

On Windows, type cd for the working current path.

On Linux, pwd for the current working path.

Which command should you use to display the current path of your current directory?

answered Sep 29, 2016 at 11:04

Which command should you use to display the current path of your current directory?

1

Which command should you use to display the current path of your current directory in Linux?

Use the pwd command to write to standard output the full path name of your current directory (from the /(root) directory).

What is the command to display directory paths?

The pwd command displays the full, absolute path of the current, or working, directory.

Which command should you use to list all files of your current directory?

To list all files in the current directory, type the following: ls -a This lists all files, including. dot (.) ... .
To display detailed information, type the following: ls -l chap1 .profile. ... .
To display detailed information about a directory, type the following: ls -d -l ..

Which command should you use to display the current path of your current directory in shell?

To determine the exact location of the current directory at a shell prompt and type the command pwd. This example shows that you are in the user sam's directory, which is in the /home/ directory. The command pwd stands for print working directory.