A description of the use of a For statement in batch processing and learning techniques _dos/bat
Source: Internet
Author: User
Batch bat in the role of the for command, very good, can save a lot of efficiency, it can read the article is not a row, the Loop ping command, the old explore the port, Learning batch processing if not learn for will be a pity, I hope you see more for the actual application of the example, If only look at the simple basis of the use of methods, and the lack of practical applications, no more than the basis is not, must first look at the example and look at the foundation, with the problem to see the basis, I believe that soon we can get started, the site has a lot of such resources, we can search
Below I will put the basic parameters of the for command, we can in the study of the DOS in the play for/? To see Help, this is how everyone comes here.
For
Runs the specified command on each file in a set of files.
Grammar
For{%variable|%%variable}in (Set) docommand[commandlineoptions]
Parameters
{%variable|%%variable}
Necessary. Represents a replaceable parameter. Use%variable to execute the for command from the command prompt. Using%%variable in batch processing
File to execute the for command. Variables are case-sensitive and must be represented by alpha values, for example,%A,%b, or%c.
(Set)
Necessary. Specifies one or more files, directories, numeric ranges, and text strings to be processed with the specified command. Parentheses are required.
Command
Necessary. Specifies the command to be executed for each file, directory, numeric range, or text string that is included in the specified (Set).
CommandLineOptions
Specifies any command-line options to use with the specified command.
/?
Displays help at the command prompt.
Comments
• Use for
You can use the for command in a batch file or directly from a command prompt.
• Working with batch parameters
The following properties apply to the for command:
The for command replaces%variable or%%variable with each text string specified in set until the command finishes processing all
File.
The forvariable name is case-sensitive, global, and has a total of no more than 52 per activity.
• To avoid confusing batch parameters%0 to%9, you can use any character other than digits 0 through 9 for variable. For the simple
batch files, a single character can take effect, such as%%f.
• Multiple variable values can be used in complex batch files to differentiate between replaceable variables.
• Specify a set of files
Set parameters can represent individual or multiple filegroups. You can use wildcard characters (that is, * and?) to specify filegroups. The following are valid file groups:
(*.doc)
(*.doc*.txt*.me)
(JAN*.DOCJAN*.RPTFEB*.DOCFEB*.RPT)
(ar?? 1991.*ap?? 1991.*)
When the for command is used, the first value in the set replaces%variable or%%variable, and the value is processed by the specified command.
This lasts until all the files (or filegroups) corresponding to the set value are processed.
• Use in and do keywords
In and do are not parameters, but they must be used with the for. If you omit any of these keywords, you receive an error message
。
• Use for other formats
If you enable command extensions, which are the default settings, the following other formats are supported for:
• Directory only
If the set contains wildcard characters (* and?), each directory that matches the set (not the filegroup in the specified directory) is executed
Use an iteration variable to set the starting value (start#), and then step through a range of values until the value exceeds the set termination value (end#)
。 /L The iteration variable is executed by comparing the start# with the end#. If the start# is less than end#, the command is executed.
If an iteration variable exceeds end#, the command interpreter exits the loop. You can also use negative step# to gradually hold the value in descending order
The value in this range of rows. For example, (1,1,5) generates sequence 12345, whereas (5,-1,1) generates a sequence (54321). Grammar is
Use file resolution to process command output, strings, and file contents. Use an iteration variable to define the content or string to check, and use the
The ParsingKeywords option further modifies the parsing method. Use the ParsingKeywords token option to specify which tokens should be used as
The iteration variable is passed. Please note that if you do not use the token option,/F will only check the first token.
The file resolution process involves reading output, string, or file content, dividing it into separate lines of text, and then parsing each row into 0 or more
A token. The For loop is then invoked by the value of the iteration variable set to the token. By default,/F passes every line of each file
A blank separator symbol. skipping blank lines. The different points of the syntax are:
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.