Get directory containing the currently executed batch script

I use %0 in batch file to get the containing directory of the batch file but the result is :-

c:\folder1\folder2\batch.bat

I want just directory, without batch file name, like this :-

c:\folder1\folder2\

How can I do it? Maybe I should filter the path. If yes, how can I do it?


%~p0

Will return the path only.

%~dp0

Will return the drive+path.

More info on the subject can be found on Microsoft's site.

Information about this syntax can also be found in the help for the for command by executing for /? on a Windows OS.


The current directory is held in %CD%