Change current directory to the batch file directory

Solution 1:

Ok, I think I found here what you mean with %~dp.

I think what you really want to do is this:

cd /D "%~dp0"

(!) But note that this will still not give you the right behaviour when you're trying to execute your batch while the current directory is on another drive as cd doesn't change the active drive.

Edit: Apparently (thanks @Yoopergeek) you can add the /D parameter to the cd command to let it also change the active drive.

Solution 2:

I'd leave a comment to fretje's answer, but evidently I can't???


Anyway, regarding the note:
But note that this will still not give you the right behaviour when you're trying to execute your batch while the current directory is on another drive as cd doesn't change the active drive.


Use the /D switch in your CD command, and CD will change the active drive.