rajeshkumar created the topic: %~dp0 VS %cd%
Use of %~dp0 and Use of %cd%
They are not equivalent.
%cd% is available either to a batch file or at the command prompt and expands to the drive letter and path of the current directory (which can change e.g. by using the CD command)
%~dp0 is only available within a batch file and expands to the drive letter and path in which that batch file is located (which cannot change). It is obtained from %0 which is the batch file’s name.
An experiment like the following shows the difference
Here is D:\dirshow.bat:
@echo off
echo this is %%cd%% %cd%
echo this is %%~dp0 %~dp0
Run it from C:\ and this is what you see
C:\>D:\dirshow.bat
this is %cd% C:\
this is %~dp0 D:\
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024
- Introduction to System Operations (SymOps) - October 30, 2024