cmd for usage in

In the cmd window for input /? After the original text, is my own "translate" a bit more like people any more.

Recommended to https://www.cnblogs.com/cbugs/p/8992059.html this tribal Gerry to see, speak better.

 

Input for the cmd window /? After

 

Original "translated"

Each file on a group of files to execute a specific command.

 

The basic format:

FOR %variable IN (set) DO command [command-parameters]

instruction

meaning

%variable

Specify the parameters of a single letter can be replaced.

(set)    

Specify one or a group of files. You can use wildcards.

command

Specified command for each file.

command-parameters

Command-line switches, or specify parameters for a specific command.

   

note:

To use the FOR command in a batch program, specify the variable use %% variablem, rather than using% variable.

Further, the variable names are case sensitive, so different from% i% I.

 

 FOR command supports the following form:

 

/ D directory

FOR /D %variable IN (set) DO command [command-parameters]

 Searches the current directory rather than a file, you can specify a wildcard.

 

/ R recursive

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

To [drive:] path is the root, execute the FOR statement for each directory.

If no directory in the specification / R, then the current directory.

If set is just a single point (.) Character, then enumerate the directory tree.

 

/ L increment sequence

FOR /L %variable IN (start,step,end) DO command [command-parameters]

This represents a sequence of digits set in increments from the start to the end.

Therefore, (1,1,5) to produce a sequence of 12 345, (5, 1,1) to generate a sequence of (54321)

 

/ F text, command analysis

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]

FOR /F ["options"] %variable IN ("string") DO command [command-parameters]

FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

 

If there usebackq options will be written in the following format:

FOR /F ["options"] %variable IN ("file-set") DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

 

fileset resolve one or more file names.

String Parsing a string

conmmand parse a result of the command, and tokens can even specify the line to make an order to get results.

 

Each file in the fileset have been opened, read and processed.

File reading processing will be divided into lines of text, and then parsing each line into zero or more symbols.

Finally, the symbol string variable values ​​have been found to call the For loop. 

 

By default, / F passes the first blank symbol in each line of each file separately. Skip blank lines.

You can add a string after the / F, its content and significance as follows:

"options" content

significance

col = c  

Specifies the end of a line comment character (just one). For example eol =; - ignore those lines to begin with a semicolon.

skip=n   

Specifies the number of lines to ignore at the beginning of the file. For example skip = 2 - 2 rows ignored

delims=xxx

Specify the delimiter, there may be a plurality.

tokens=x,y,m-n

It means a symbol which is transmitted to each line for each iteration itself. This leads to assign additional variable names.

Mn may be used to specify a range variable.

If you specify the last character is an asterisk, then an additional variable will be assigned to a variable after the last remaining understand that line of text.

usebackq

If the specified file name has spaces, it needs to be escaped.

However, the use of '' or '' is understood to be a string or command.

So add this parameter to specify a new way of escape.

 

 

Example:

FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k

 

Each row of the analysis myfile.txt, ignoring lines that begin with a semicolon, each row in the second and third symbols for transfer to the body of the function delimiter designated as "" or spaces.

This statement is a reference for the function body to obtain a second% i symbol,% j to obtain a third token, and% k to get all remaining tokens after the third symbol.

For file names with spaces, you need to use double quotes to enclose the file name in order to use this way to use double quotes, also you need to use usebackq option.

Otherwise the double quotes will be interpreted as defining a literal string to parse.

 

% I explicitly declared in the for statement,% j and% k tokens = option through implicit declarations.

You can specify up to 26 tokens by tokens = line, do not try to declare a variable higher than the letter "z" or "Z" is.

Remember, FOR variables are single-letter, case sensitive, global variables are; moreover, can not use more than 52.

 

Example:

FOR /F "usebackq" %i in ('abc') do echo %i

Abc Print

 

 

May also be used FOR / F in the adjacent string analysis logic, method is to use single quotes file-set between brackets.

In this way, the string will be treated as a single input line of a file parsing.

 

Can output FOR / F command to parse the command.

Is to use back quotes string, the string is treated as a command line, which is output to the results of the command memory and as file analysis.

 

Example:

FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i

枚举当前环境中的环境变量名称。

 

另外,FOR 变量参照的替换已被增强。你现在可以使用下列

选项语法:

 

     %~I          - 删除任何引号("),扩展 %I

     %~fI        - 将 %I 扩展到一个完全合格的路径名

     %~dI        - 仅将 %I 扩展到一个驱动器号

     %~pI        - 仅将 %I 扩展到一个路径

     %~nI        - 仅将 %I 扩展到一个文件名

     %~xI        - 仅将 %I 扩展到一个文件扩展名

     %~sI        - 扩展的路径只含有短名

     %~aI        - 将 %I 扩展到文件的文件属性

     %~tI        - 将 %I 扩展到文件的日期/时间

     %~zI        - 将 %I 扩展到文件的大小

     %~$PATH:I   - 查找列在路径环境变量的目录,并将 %I 扩展

                   到找到的第一个完全合格的名称。如果环境变量名

                   未被定义,或者没有找到文件,此组合键会扩展到

                   空字符串

 

可以组合修饰符来得到多重结果:

 

     %~dpI       - 仅将 %I 扩展到一个驱动器号和路径

     %~nxI       - 仅将 %I 扩展到一个文件名和扩展名

     %~fsI       - 仅将 %I 扩展到一个带有短名的完整路径名

     %~dp$PATH:I - 搜索列在路径环境变量的目录,并将 %I 扩展

                   到找到的第一个驱动器号和路径。

     %~ftzaI     - 将 %I 扩展到类似输出线路的 DIR

 

在以上例子中,%I 和 PATH 可用其他有效数值代替。%~ 语法

用一个有效的 FOR 变量名终止。选取类似 %I 的大写变量名

比较易读,而且避免与不分大小写的组合键混淆。

Guess you like

Origin www.cnblogs.com/kvii/p/11641155.html
cmd