Sometimes we see people using%~DP0.
~ is the meaning of extension, which is equivalent to converting a relative path to absolute path
%0 refers to the batch file itself
%1 represents the first parameter that the batch file command line received,%2 represents the second, and so on
%~d0 refers to the letter in which the batch is located, where D represents the drive
%~p0 refers to the directory where the batch is processed, where p represents path
%~DP0 is the disk alphanumeric path where the batch process resides
CD%~dp0 is the directory where the batch is being processed.
Detailed explanation also can refer to command call/?
What does%~dp0 mean in DOS batch processing?
(Note:%0 is the filename of the batch file)
The meaning of this sentence is
Change the current directory as a directory for the batch process itself
A little dizzy, huh? No hurry, I'll give you an example
Like you have a batch a.bat under the D:/qq folder.
A.bat content is
CD/D%~dp0
Over here
cd/d%~dp0 means cd/d d:/qq.
%0 Represents the batch process itself D:/qq/a.bat
~DP is a variable extension
D is both extended to the Sub area code D:
P is extended to path/QQ
DP is extended to the sub-area code path D:/QQ
extended variable Syntax:
:: Option Syntax:
:: ~i-Remove any quotes ("), expand%I
::%~fi-Will%I Extend to a fully qualified path name
::%~di-%I only Expand to a drive letter
::%~pi-%I only Extend to a path
::%~ni-%I only Extend to a filename
::%~xi-%I only Extended to a file name extension
::%~si-Extended path contains only short names
::%~ai-Will%I File attributes extended to files
::%~ti-Will%I Date/time of expansion to file
::%~zi-Will%I Expand to the size of the file
::% $PATH: I-Find directories listed in PATH environment variables, and%I Expand
:: To the first fully qualified name found. If the environment variable name
:: Not defined, or file not found, this key combination expands to
:: Empty string
:: You can combine modifiers to get multiple results:
::%~dpi-%I only Extend to a drive letter and path
::%~nxi-%I only extended to a filename and extension
::%~FSI-%I only Extended to a full pathname with a short name
::%~DP$PATH:I-Find directories listed in PATH environment variables, and%I Expand
:: To the first drive letter and path found.
::%~ftzai-Will%I DIR extended to a similar output line
The following is an instance resolution:
If a Install.bat file is located in the D:\jeesite\bin
The contents of the document are as follows:
@echo off the
echo [INFO] This is a demo.
echo [INFO]%~dp0
Pause
Run Install.bat, the command line output is as follows
[INFO] This is a demo.
[INFO] D:\jeesite\bin\
That
%0 represents the file itself
D represents the letter
P represents path
The extended options also include:
%~F0-Full path + filename
[INFO] D:\jeesite\bin\install.bat
%~n0
-filename (no extension)
[INFO] Install
%~x0
-File name extension
[INFO]. bat
%~S0-The extended path contains only short names ("s" as short, shorter)
%~A0-Will%0 File attributes extended to file ("a" attribute, that is, attributes)
%~t0-Will%0 Date/Time extended to file ("T" times)
%~z0-Will%0 Expand to file size (size)
Wait a minute