In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use the FOR statement in batch processing. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The function of the for command in batch bat is very good, and it can save a lot of efficiency. It can read every line of the article, execute ping commands in a loop, always explore ports, and learn batch processing. It will be a pity if you do not learn for. I hope you will take a look at more examples of the practical application of for commands. If you only look at the simple basic usage, but lack of practical application, no amount of foundation can be formed. Must first look at the examples and then look at the foundation, with questions to look at the foundation, I believe that soon everyone can get started, this site has a lot of such resources, you can search
Next, I will sort out the basic parameters of the for command. When you study, you can type for /? under dos. Come and see the help. That's 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 replaceable parameters. Use% Variable to execute the for command from the command prompt. Using Variable in batch processing
Execute the for command in the file. Variables are case sensitive and must be represented by alpha values, such as% 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 on each file, directory, numeric range, or text string included in the specified (Set).
CommandLineOptions
Specify any command line options to use with the specified command.
/?
Displays help at the command prompt.
Annotation
Use for
You can use the for command in a batch file or directly from a command prompt.
Use 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 Command has processed all
Until the file.
ForVariable names are case-sensitive, global, and there are no more than 52 activities at a time.
To avoid confusing the batch parameters% 0 through% 9, use any character except the numbers 0 to 9 for Variable. For simple
For batch files, a single character can take effect, such as% f.
Multiple Variable values can be used to distinguish different replaceable variables in complex batch files.
Specify a set of files
The Set parameter can represent single or multiple filegroups. You can use wildcards (that is, * and?) to specify filegroups. The following are valid filegroups:
(* .doc)
(* .doc * .txt * .me)
(jan*.docjan*.rptfeb*.docfeb*.rpt)
(ar??1991.*ap??1991.*)
When using the for command, the first value in Set replaces% Variable or% Variable, which is then processed by the specified command.
This continues until all files (or filegroups) corresponding to the set value are processed.
Use the in and do keywords
In and do are not parameters, but they must be used with for. If any of these keywords are omitted, an error message will appear
.
Use other formats of for
If command extension is enabled (which is the default), the following other formats of for are supported:
Directory only
If the Set contains wildcards (* and?), the pointer is executed for each directory that matches the Set (instead of the filegroup in the specified directory)
I ordered the Command. The syntax is:
For/D {%% |%} Variablein (Set) doCommand [CommandLineOptions]
Recursion
Go to the root tree [Drive:] Path and execute the for statement in each directory of the tree. If no directory is specified after / R, it is considered to be
Current directory. If Set is just a period (.), only the directory tree is enumerated. The syntax is:
For/R [[Drive:] Path] {% |%} Variablein (Set) doCommand [CommandLineOptions]
Iterative numerical range
Use the iteration variable to set the start value (Start#), and then step through a range of values until the value exceeds the set end value (End#)
. / L will execute iterative variables by comparing Start# with End#. This command is executed if Start# is less than End#,.
If the iteration variable exceeds End#, the command interpreter exits the loop. You can also use a negative Step# to gradually execute in a decreasing number.
Row values within this range. For example, (1) generates a sequence 12345, and (5) generates a sequence (54321). The grammar is
:
For/L {%% |%} Variablein (Start#,Step#,End#) doCommand [CommandLineOptions]
Iteration and file parsing
Use file parsing to process command output, strings, and file contents. Use iterative variables to define the content or string to check, and use each
The ParsingKeywords option further modifies the parsing method. Use the ParsingKeywords token option to specify which tokens should be used as
Iterative variable passing. Note that when there is no token option, / F will only check the first token.
The file parsing process involves reading the output, string, or file contents, dividing it into separate lines of text, and parsing each line into zero or more
A token. The for loop is then called by setting the value of the iteration variable to the token. By default, / F passes the first of each line of each file
A blank separator. Skip blank lines. The differences in grammar are:
For/F ["ParsingKeywords"] {% |%} Variabelin (FileNameSet) doCommand [CommandLineOptions]
For/F ["ParsingKeywords"] {% |%} Variablein ("LiteralString") doCommand
[CommandLineOptions]
For/F ["ParsingKeywords"] {% |%} Variablein ('Command') doCommand [CommandLineOptions]
The FileNameSet parameter specifies one or more file names. Each file will be opened, read, and processed before continuing execution
The next file in FileNameSet. To override the default resolution behavior, specify "ParsingKeywords". This is enclosed in quotation marks.
That contains one or more keywords to specify different parsing options
If you use the usebackq option, use one of the following syntax:
For/F ["usebackqParsingKeywords"] {% |%} Variablein ("FileNameSet") doCommand
[CommandLineOptions]
For/F ["usebackqParsingKeywords"] {% |%} Variablein ('LiteralString') doCommand
[CommandLineOptions]
For/F ["usebackqParsingKeywords"] {% |%} Variablein ('Command') doCommand
[CommandLineOptions]
This is the end of this article on "how to use FOR sentences in batch processing". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 297
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.