The difference between%cd% and%~dp0 in DOS batch processing
In DOS batches, it is sometimes necessary to know the current path.
In DOS, there are two environment variables that can be associated with the current path, one is%cd%, and the other is%~dp0.
The usage of the two variables and the content of the representation are different.
1.%cd% can be used in batch files or in the command line;
After expansion, is the drive letter: + current directory, such as in the DOS window into the C:\dir directory, www.2cto.com
Input: Echo%cd% is displayed as: C:\dir.
The contents of the%cd% can be changed to the execution path of the command or to the execution path of the batch file.
2.%~dp0 can only be used in a batch file, it is determined by the directory location of the batch file where it resides,
is the drive letter that contains the batch file: + path. In the process of executing this batch file,
The content after it is expanded cannot be changed. For example, under the D disk there is a batch file, Path.bat, the content is:
[Plain]
@echo off
echo This is%%cd%%%cd%
echo This is%%~dp0%~dp0
In C \ And e:\ execute it separately, the output is:
The difference between%cd% and%~dp0 in DOS batch processing