Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

For loop internal %_for_files variable?

Jul
441
6
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?
 
Typically the lines of a file are not file names. I don't see any reason why FOR should count them as files.
 
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

Back
Top