Editor of parameters for a batch file (BAT) under Windows

Source: Internet
Author: User
Tags extend

The batch parameter extension variable (%0 to%9). When a batch parameter is used in a batch file, the%0 will be replaced by the batch file name, and%1 to%9 will be replaced by the corresponding parameter typed at the command line.

You can use an edit character in a batch parameter. The editor uses the current drive and directory information to extend the batch parameter to a partial or complete file or directory name. To use the edit character, type the percent sign (%) character, followed by the tilde (~) character, and then type the appropriate editor (that is,%~modifier).

The following table lists the editor characters that you can use in the extension.

Description of the edit character

%~%~1 expands%1 and removes any quotation marks (""

%~f%~f1 to extend%1 to fully qualified path name

%~d%~d1 extending%1 to drive letter

%~p%~p1 extending%1 to the path

%~n%~n1 extending%1 to file name

%~x%~x1 extending%1 to file name extension

The path to the%~s%~s1 extension contains only the short name

%~a%~a1 extending%1 to file properties

%~t%~t1 extending%1 to file date/time

%~z%~z1 extending%1 to file size

%~ $PATH:%~ $PATH: 1 searches the directory listed in the PATH environment variable and expands%1 to the fully qualified name of the first found directory. If the environment variable name is not defined or the file is not found, the editor expands to an empty string

The following table lists the possible combinations of editors and qualifiers that you can use to get complex results:

Description of the edit character

%~dp0 will%0 Extended to drive letter + path + file name + extension

%~nx1 extending%1 to file name and extension

%~dp$path:1 Search for% 1 in the directory listed in the PATH environment variable, and expand to the drive letter and path of the first found directory

%~dpn0 extension%0 to drive letter + path + file name

%~ftza1 extending%1 to output line similar to Dir

Attention:

In the example above, you can replace%1 and PATH with other batch parameters.

The%* editor is the only editor that can represent all parameters passed in a batch file. You cannot use this editor with the%~ edit character combination. The%~ syntax must be terminated by a valid parameter value.

You cannot use batch parameters in the same way as you use environment variables. You cannot search for or replace a value, or check a substring. However, you can assign a parameter to an environment variable and then use that environment variable.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.