A. Bat content is
CD/d % ~ Dp0
Here
CD/d % ~ Dp0 means CD/d: \ QQ
% 0 indicates the batch processing itself D: \ QQ \ A. bat
~ DP is Variable Expansion
D is expanded to the Partition Number D:
P is extended to the path \ QQ
DP is extended to the partition code path D: \ QQ
Extended variable syntax explanation:
::~ I-delete any quotation marks (") and expand % I
: % ~ Fi-extend % I to a fully qualified path name
: % ~ Di-only expand % I to one drive letter
: % ~ Pi-only expand % I to one path
: % ~ Ni-only expand % I to one file name
: % ~ Xi-only expand % I to one file extension
: % ~ The SI-extended path contains only short names.
: % ~ Ai-extend % I to file attributes
: % ~ Ti-extend % I to the date/time of the file
: % ~ Zi-expand % I to the file size
: % ~ $ Path: I-searches for the Directory of the environment variable in the path and expands % I to the first fully qualified name. If the environment variable name is not defined or the file is not found, the key combination is expanded to an empty string.
: You can combine modifiers to get multiple results:
: % ~ DPI-only expand % I to one drive letter and Path
: % ~ Nxi-only expand % I to one file name and extension
: % ~ FSI-only expand % I to a complete path name with a short name
: % ~ DP $ path: I-find the directory of the Environment Variable listed in the path and expand % I
: The first drive letter and path found.
: % ~ Ftzai-extended % I to the Dir similar to the output line
% ~ Dp0 vs % Cd %
% Cd % is available either to a batch file or at the command prompt and expands to the drive letter and path of the current directory (which can change e.g. By using the CD command)
% ~ Dp0 is only available within a batch file and expands to the drive letter and Path in which that batch file is located (which cannot change ). it is obtained from % 0 which is the batch file's name.
An experiment like the following shows the difference
Here is D: \ dirshow. BAT:
Code:
@ Echo off
Echo this is % Cd %
Echo this is % ~ Dp0 % ~ Dp0
Run it from c: \ and this is what you see
Code:
C: \> D: \ dirshow. bat
This is % Cd % C :\
This is % ~ Dp0 D :\