In ordinary applications of for, %a, %i, and %k are not essentially different. Only one variable is sufficient to refer to a group of files, directories, or number sequences, and multiple variable symbols will not appear simultaneously in the for statement.
But when parsing file groups using the /f parameter, the delims and tokens keywords in the "options" parameter define multiple groups of characters, and multiple variables must be used to represent them in sequence. So we often see multiple variable symbols in the for /f statement, and then there is a difference between using %a or %i.
First, let's look at a piece of help information about for /f variables:
"%i is specifically explained in the for statement, and %j and %k are specifically explained through the tokens= option. You can specify up to 26 symbols in a tokens= line, as long as you don't try to explain a variable higher than the letter 'z' or 'Z'. Remember that FOR variables are single letters, case-sensitive, and global; and at the same time, no more than 52 can be in use."
Here it is mentioned that only 26 symbols can be defined, that is, at most 26 variable symbols can appear in the for /f statement. If the first variable is defined as %a, the second is %b, and so on, the last one is %z, and the total number of variables is 26; while if the first variable is defined as %i, the second can only be %j, and the last one is still %z, but the number of definable variables is reduced by 8, leaving only 18.
The following example can intuitively show the difference:
If the format of the 3.txt file is as follows:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
Then for /f "tokens=1-30 delims=," %a in (3.txt) do echo a%,%z will see 1,26, while for /f "tokens=1-30 delims=," %i in (3.txt) do echo i%,%z will see 1,18 (numbers after 18 cannot be defined).
[ Last edited by hizebra on 2007-10-11 at 05:53 PM ]
Recent Ratings for This Post
( 3 in total)
Click for details