Windows Bat of the For loop
1. For basic usage cycle.
1.1 Format
In the cmd window:
FOR %variable IN (set) DO command [command-parameters]
In Bat file:
FOR %%variable IN (set) DO command [command-parameters]
Note the point: 在cmd窗口中,for之后的形式变量I必须使用单百分号引用,即%i;而在批处理文件中,引用形式变量i必须使用双百分号,即%%i。
the basic elements For what are some statements:
1, for, in and do a keyword for statement, three of them are indispensable;
2, %% is for the I referenced in the statement of the form variable, even if it not involved in the execution of the statement in the statement after the do, but also must appear;
3, then in, do before the parentheses can not be omitted;
4, the SET represent strings, or variables, command string that represents the variable or command statement;
1.2 View Windows help file
Use for /? Either view
1.3 practical example
1.3.1 list all txt files in the current path.
for %%i in (??.txt) do echo "%%i"
1.3.2 text parsing significant for / f usage.
1) the value of the command line is assigned to the variable.
for /f %i in ('wmic ComputerSystem get Manufacturer ^|find /v "Manu" ^| findstr .') do (set type=%i)
2) Use "delims =" delimiter specified, / f is the default key space or Table as a separator.
for /f "delims=," %i in ('wmic ComputerSystem get Manufacturer ^|find /v "Manu" ^| findstr .') do (set type=%i)