[Http://www.cnblogs.com/smwikipedia/archive/2009/03/30/1424749.html]
[Http://www.911cd.net/forums/lofiversion/index.php/t3730.html]
Change the current directory to the batch processing Directory.
Are you dizzy? Don't worry, I will give an example
For example, if you have batch processing a. bat in the D: \ QQ folder
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:
: Option Syntax:
::~ 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-find the directory of the environment variable in the path and expand % I
: The first fully qualified name found. If the environment variable name
: Not Defined, or the file is not found. This key combination is extended
: 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
----------------------------
Http://www.911cd.net/forums/lofiversion/index.php/t3730.html
Look at this:
Manipulating variables in cmd Shell
I'm not sure why this type of information isn't more prominent in the help files, but there you go. NT's command shell can manipulate variables but the operations you can perform are fairly limited. still, better than nothing. if you want to do some really clever stuff then you're going to have to look elsewhere. VBScript can be useful as it's got lots of string handling capabilities. there's also Perl and awk which are windows (LOGIN Ze ?) Ports of some very powerful Unix commands.
% 1 is your command line option.
Namely: mycommand. CMD myoption1.
% 0 determins where the batch file is running from. I 've created a demo batch file in my winnt system32 folder called X. cmd. Running this gives the results shown below
% ~ F1 expands % 1 to the drive, path and file name. If you pass % 1 from the current directory then this expands that variable to it's full path
Echo f0 = % ~ F0 produces f0 = c: \ winnt \ system32 \ x. cmd
% ~ D1 gets the drive letter from % 1
Echo D0 = % ~ D0 produces D0 = d
% ~ P1 extracts the path from variable % 1
Echo p0 = % ~ P0 produces \ winnt \ system32 \
% ~ Dp1 pulls the drive letter and Path
Echo dp0 = % ~ Dp0 produces c: \ winnt \ system32 \
% ~ SP1 creates a short path (but no drive letter)
Echo sp0 = % ~ Sp0 produces \ winnt \ System32
If I set % 1 to "C: \ Program Files \ Internet Explorer" then % ~ SP1 produces \ progra ~ 1 \ inter. note you have to wrap the long path in quotes otherwise the truncation doesn't work.
% ~ X1 leaves only the command Extension
Echo X0 = % ~ X0 produces. cmd
% ~ Nx1 extracts the file name and extension
Echo nx0 = % ~ Nx0 produces X. cmd
% ~ SX1 extracts the short extension from % 0
Echo sx0 = % ~ Sx0 produces. CMD but a longer extension (.doc ument ?) Wocould be cut down to. Doc
----------------------------
% ~ Dp0 vs % Cd %
Http://www.computerhope.com/forum/index.php? Topic = 54333.0
% 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 :\