I find %~dp0
very useful, and I use it a lot to make my batch files more portable.
But the label itself seems very cryptic to me… What is the ~
doing? Does dp
mean drive and path? Does the 0
refer to %0
, the path to the batch file that includes the file name?
Or it is just a weird label?
I'd also like to know if it is a documented feature, or something prone to be deprecated.
Best Solution
Calling
in the command-line gives help about this syntax (which can be used outside FOR, too, this is just the place where help can be found).
There are different letters you can use like
f
for "full path name",d
for drive letter,p
for path, and they can be combined.%~
is the beginning for each of those sequences and a numberI
denotes it works on the parameter%I
(where%0
is the complete name of the batch file, just like you assumed).