The difference between%cd% and%~dp0 in DOS batch processing, sometimes you need 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, also can be used in the command line, after expansion, is the drive letter: + The 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 of the batch file: + path. In the process of executing this batch file, the content after its expansion cannot be changed. For example, under the D disk there is a batch file, Path.bat, the contents are: [plain] @echo off echo This is the%%cd%%%cd% echo this is%%~dp0%~dp0 in c \ And e:\ execute it separately, the output is:
Author yxyy3604
The difference between%cd% and%~dp0 in DOS batch processing