%~dp0 and other extended variable syntax in DOS batch processing _dos/bat

Source: Internet
Author: User

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

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.