This is an in-depth look at batch script's for /f loop, especially use of tokens attribute.
We go through several examples of how to use for /f loop by tweaking tokens attribute.
For example:
for /f "tokens=* delims= " %%a in ("a b c d e f g") do (
echo %%a
)
will unexpectedly return output
a b c d e f g
You may have guessed there will be 7 different tokens but there is one "a b c d e f g".
Also the following two for loops do the same thing:
for /f "tokens=*" %%f in (files.txt) do (
echo copy %%f to a new location
)
and
for /f "delims=" %%f in (files.txt) do (
echo copy %%f to a new location
)
where files.txt:
abc.dat
def.dat
ghi.dat
and output
copy abc.dat to a new location
copy def.dat to a new location
copy ghi.dat to a new location