For loop internal %_for_files variable?


Jul 6, 2008
As shown in the following, when using the @set with the FOR command, the internal variable %_for_files isn't set and when using the wildcard *, the %_for_files is in fact set as documented.
I noticed this while updating a very old batch file to take advantage of the newer TCC features.
This is true as far back as v17.

TCC  24.00.36 x64   Windows 10 [Version 10.0.17763.253]

v24.00.36_$unset count
v24.00.36_$for %XX in (@descript.ion) DO (echo %@word[0,%xx] > nul & *set count=%@inc[%count]) & echo ^t file count === %count
         file count === 44
v24.00.36_$for %XX in (@descript.ion) DO (echo %@word[0,%xx] > nul) & echo ^t file count === %_for_files
         file count === 0
v24.00.36_$for /I"[?]*" /a: %XX in (*) DO (echo %@word[0,%xx] > nul) & echo ^t file count === %_for_files
         file count === 44

What's up?
May 20, 2008
Syracuse, NY, USA
Typically the lines of a file are not file names. I don't see any reason why FOR should count them as files.


Staff member
May 14, 2008
Vince is correct - if you're using the @file syntax to retrieve lines, FOR will treat it as string substitution, not as a sequence of filenames.

The %_file_count variable is only incremented if you specify a wildcard name, or a /W to indicate that a non-wildcarded name should be treated as a filename.
Similar threads
Thread starter Title Forum Replies Date
old coot LEAVE in a DO /S fileset loop only leaves one subdirectory Support 4
samintz How to? Abort on error DO loop Support 10
D How to use multi-line DO to loop through first level directory names Support 5
vefatica ON ERROR terminates DO loop. Support 0
Dick Johnson for ... do loop "wrap around" Support 11
vefatica Modifying a counted DO loop's counter? Support 1
Z [dos] into - for loop - the bp is not hit Support 5
vefatica Piping the output of a DO loop. Support 4
D What is the limit on the compound statement length within ( ) of a FOR-loop? Support 5
old coot Proper use of ON ERRORMSG inside a DO WHILE loop? Support 3
H EndLocal in DO Loop Support 2
B How to? redirect a bunch of loop Support 4
Mike Hall Unexpected "Variable loop" in IF condition Support 10
C FOR loop with nested IF / IFF Support 9
D Strange issue with FOR loop Support 15
nickles WAD Variable name gets changed within FOR loop Support 2
M tcmd crashes in this recursive "for /f" loop Support 4
G Fixed Slow FOR loop Support 2
S WAD %_do_errors does not report errors when loop control variable type is not directory entry Support 1
mikea 'Loop' on closing TC Support 6
Roedy Loop anomaly Support 6
R nested for loop question Support 3
P Need to use a regex in a "for" loop. Support 54
Alpengreis (Internal) support for CPython v3.10? Support 2
fpefpe How to? free (internal) command Support 0
Joe Caverly Documentation Replace internal command with LIBRARY command Support 0
T Returning a value from internal Lua scripts to TCC Support 2
Joe Caverly Why does TCCRT return VIEW as an internal command? Support 6
F How to? Disable TCC's internal response to Alt-F4 Support 8
vefatica @EVAL's internal precision? Support 9
jfalch WAD internal "which" should check for FILEEXIST when using AppPaths entry Support 8
P Can't disable internal tar, at least in pipes Support 3
M Keywords for commands, functions, internal variables Support 3
D WAD Internal variable _cpu is undefined Support 2
E View (internal command) does nothing now Support 3
D Minor problem. Incorrect value internal var _dir_files Support 7
jbanaszczyk Alias for internal command Support 8
Joe Caverly Internal Lua and require Support 0
R Fixed Internal ZIP command fails to process multiple files Support 3
D Internal variable _tctabs within TCExit Support 9
mikea Questions re: Internal ZIP command Support 5
epement no internal help for 'v' in TCmd v14 Support 6
R Override TCC internal commands Support 2
H [4NT8] Internal Start-command and _? variable Support 5
G 4NT 9.02 _shell internal variable Support 50
MickeyF TCC crashing when copying multiple files (now resolved) Support 6
fpefpe How to? shortcuts and batch files Support 4
C v28 key files Support 2
J ffind does not find files Support 4
C duplicate files in multiple plugin sites Support 9

Similar threads