In DOS batches, it is sometimes necessary to know the current path. In DOS, there are two environment variables that can relate to the current path, one is%cd%, and the other is%~dp0.
The use of these two variables and the content of the representation are different.
1.%cd% can be used in a batch file or in a command line; When expanded, the drive letter: + current directory, such as in the DOS window into the C:\dir directory,
Input: Echo%cd%, which is displayed as: C:\dir.
The contents of the%cd% can be changed to the execution path of the command or the execution path of the batch file.
2.%~dp0 can only be used in a batch file, which is determined by the directory location of the batch file in which it resides, and is the disk character of the batch file: + path. In the process of executing this batch file, the content that it expands can not be changed. For example, under D disk, there is a batch file, Path.bat, which reads:
Copy Code code as follows:
@echo off
echo This is%%cd%%%cd%
echo This is%%~dp0%~dp0
In C:\ and E:\ to execute it separately, the output is: