Reputation: 149
I have a batch script on a CD. Whenever I try to run it and enter %~d0
, it returns the C: drive instead of F:, which is my CD drive.
What is a way to find the drive letter?
Upvotes: 14
Views: 27409
Reputation: 3862
Get the drive letter from the current directory with:
%cd:~0,2%
%~dp0 is pretty useful in a bat: it is the folder in which the executing bat file resides.
Perhaps at the top of your script, do something like:
set _SCRIPT_DRIVE=%~d0
set _SCRIPT_PATH=%~p0
and then echo it out to debug. %~d0 should be giving you what you want, but the other options I mentioned might be helpful in solving the challenge.
Upvotes: 26