logo

How to Check the Directory Location of the Batch Command 📂Programing

How to Check the Directory Location of the Batch Command

Code 1

C:\Users\rmsms\OneDrive\lab\DynamicalSystems\loading.bat

Suppose a file like the above was executed. The contents of this batch command are as follows.

@echo off
echo %cd%
echo %~dp0
echo %~f0
pause

Output

C:\Users\rmsms\OneDrive\lab\DynamicalSystems
C:\Users\rmsms\OneDrive\lab\DynamicalSystems\
C:\Users\rmsms\OneDrive\lab\DynamicalSystems\loading.bat
  • %cd%: denotes the directory where the file was actually executed.
  • %~dp0: the directory of the executed file, shown with a trailing backslash.
  • %~f0: represents the full path of the file.

For reference, combinations that include ~ follow the same rules as batch command input parameters.