In DOS batch processing, you sometimes need to know the current path. In DOS, two environment variables can be related to the current path. One is % cd %, and the other is % ~ Dp0.
The usage and content of these two variables are different.
1.% cd % can be used in batch files or in command lines. After expansion, it is the drive letter: + current directory. For example, enter c in the dos window: under the \ dir directory,
Input: echo % cd %, displayed as: c: \ dir.
The content of % cd % can be changed. The content is the command execution path or the execution path of the batch file.
2.% ~ Dp0 can only be used in batch files. It is determined by the directory location of the batch files it is located in. It is the drive letter of the batch files: + path. During the execution of this batch file, the expanded content cannot be changed. For example, there is a batch processing file named path. bat in disk D, whose content is:Copy codeThe Code is as follows: @ echo off
Echo this is % cd %
Echo this is % ~ Dp0 % ~ Dp0
Run it in C: \ and E: \ respectively, and the output is: