Windows Script-% ~ Dp0 meaning

Source: Internet
Author: User

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 :\

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.