This question already has an answer here:
-
What does %~dp0 mean, and how does it work?
7 answers
Can someone please help me to understand the command cd /d %~dp0
and its purposes. Again dos command is below
cd /d %~dp0
Please help me to get the meaning of it.
Let's dissect it. There are three parts:
cd
-- This is change directory command.
/d
-- This switch makes cd
change both drive and directory at once. Without it you would have to do cd %~d0 & cd %~p0
.
%~dp0
-- This can be dissected further into three parts:
%0
-- This represents zeroth parameter of your batch script. It expands into the name of the batch file itself.
%~0
-- The ~
there strips double quotes ("
) around the expanded argument.
%dp0
-- The d
and p
there are modifiers of the expansion. The d
forces addition of a drive letter and the p
adds full path.
~dp0 : d=drive, p=path, %0=starting directory of this batch-file
cd /d %~dp0
will change the path to the same, where the batchfile resides
See for /?
for more details