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?
Use the pwd command to write to standard output the full path name of your current directory (from the /(root) directory). All directories are separated by a slash (/). The /(root) directory is represented by the first slash (/), and the last directory named is your current directory.
The answer is the pwd command, which stands for print working directory. The word print in print working directory means “print to the screen,” not “send to printer.” The pwd command displays the full, absolute path of the current, or working, directory.
Go to the destination folder and click on the path (highlights in blue). type cmd. Command prompt opens with the path set to your current folder.
So if you are in your home directory the full path is s.th. like /home/sosytee/my_script . For your home directory there is the "short-cut" ~ , meaning you can also write ~/my_script . But that will of course resolve to a different path for every user.
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).
You can set a batch/environment variable as follows:
SET var=%cd% ECHO %var%
sample screenshot from a Windows 7 x64 cmd.exe.
Update: if you do a SET var = %cd%
instead of SET var=%cd%
, below is what happens. Thanks to jeb.
Capturing the current directory from a batch file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With