For loop internal %_for_files variable?

rps

Jul 6, 2008
388
4
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.

Code:
v24.00.36_$ver
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?
 

rconn

Administrator
Staff member
May 14, 2008
11,020
98
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.