How can i get the current path in .cmd file?
I see a ton of people saying
oh just use "cd"
To get the value of cd
, I have to set it first, which i can't as i am making it portable.
I wonder if there is any built-in variable which tell the current path of .cmd script file
like:
(C:\test.cmd)
echo %cur-path%
>> C:\
I've been searching for the internet for an hour and I can't find a solution others then "cd", "%cd".
A simple "no" will be acceptable
Put this code in your .cmd script file(save as whatevername.cmd
):
echo %~dp0
Now run it in cmd:
directory of .cmd script file\whatevername.cmd
Pretend that the .cmd script file was in C:\\Users\\User\\Documents
folder. Then the output will be:
C:\Users\User\Documents\
I hope this is what you were looking for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.