Is there a Windows command line command that I can use to get the full path to the current working directory? Show
Also, how can I store this path inside a variable used in a batch file?
asked Mar 3, 2009 at 19:03
2 Use
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:
sample screenshot from a Windows 7 x64 cmd.exe. Update: if you do a 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 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 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:
Danny Beckett 19.9k23 gold badges105 silver badges134 bronze badges answered Mar 3, 2013 at 0:29
Fred ScalesFred Scales 3073 silver badges2 bronze badges 3 For Windows we can use
and for Linux
command is there. answered Oct 1, 2013 at 13:46
Nikunj K.Nikunj K. 8,3294 gold badges42 silver badges52 bronze badges Create a
Explanation:
Now answered Sep 12, 2018 at 18:57
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.
answered Aug 17, 2015 at 17:01
Ajay JayavarapuAjay Jayavarapu 4611 gold badge6 silver badges16 bronze badges For Windows, For UNIX and workalike systems, 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, If we want to copy the path then we can use:
answered Jan 30, 2016 at 10:09
But, of course, gmaran23's answer is the much easier one. answered Jul 4, 2013 at 8:30
René NyffeneggerRené Nyffenegger 38.5k32 gold badges155 silver badges275 bronze badges 2 As one of the possible codes
answered May 24, 2020 at 10:12
GarricGarric 5413 silver badges9 bronze badges On Windows, type On Linux,
answered Sep 29, 2016 at 11:04
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.
|