A collection of batch parameters that can be used _dos/bat

Source: Internet
Author: User
Tags modifier
You can use batch parameters anywhere within a batch file to extract information about your environment settings.

Cmd.exe provides batch parameter extension variables (%0 to%9). When a batch parameter is used in a batch file,%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. To access parameters larger than%9, you must use the SHIFT command. For more information about the shift command, see shift. The%* batch parameter is a wildcard character that can be referenced by all parameters (excluding%0), which are passed to the batch file.

For example, to copy the contents of Folder1 to Folder2, where%1 and%2 will be replaced by value Folder1 and Folder2 respectively, type the following in the batch file Mybatch.bat:

xcopy%1\*.*%2

To run the file, type:

Mybatch.bat C:\folder1 D:\folder2

This is equivalent to typing the following in a batch file:

xcopy C:\folder1 \*.* D:\folder2

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

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

Editor description
%~1 extension%1 and remove any quotes ("").
%~f1 expands%1 to a fully qualified pathname.
%~d1 extends%1 to the drive letter.
%~P1 extends%1 to the path.
%~n1 expands%1 to the filename.
%~x1 extends%1 to the file name extension.
The path to the%~S1 extension contains only short names.
%~A1 expands%1 to a file attribute.
%~t1 extended%1 to the file date/time.
%~Z1 expands%1 to a file size.
~ $PATH: 1 Search the directory listed in the PATH environment variable and extend%1 to the fully qualified name of the first directory found. 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 can be used to get complex results:

Editor description
%~DP1 extends%1 to the drive letter and path.
%~nx1 extends%1 to the filename and extension.
%~dp$path:1 searches for% 1 in the directory listed in the PATH environment variable and expands to the drive letter and path of the first directory found.
%~ftza1 extends%1 to an output line similar to Dir.

Attention

In the example above, you can replace%1 and PATH with other batch parameters.
The%* modifier is the only editor that can represent all parameters passed in a batch file. You cannot use this modifier in combination with the% ~ Modifier. The ~ syntax must be terminated by valid parameter values.

Batch parameters cannot be used in the same way as using environment variables. You cannot search or replace values, or check substrings. However, you can assign parameters to an environment variable and then use that environment variable.

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.