Get current dir path in BATCH file


How to get current path in batch file. Here some example shows the different ways:

@echo off
setlocal enableextensions enabledelayedexpansion

set currDir1=%~dp0
set currDir2=%CD%

echo %currDir1%
echo %currDir2%

pause

And the output:

C:\Windows\System32>D:\Run\1.bat
D:\Run\
C:\Windows\System32
Press any key to continue . . .

So, as you can see, method with %~dp0 is more preferable if you run from anywhere but script placed.