Can anyone please explain exactly how the following code works, line by line. I’m really lost. I’ve been trying to learn how to use the FOR command but I don’t understand this.
@echo off
for /f "tokens=* delims= " %%f in (myfile) do (
set line=%%f
call :processToken
)
goto :eof
:processToken
for /f "tokens=1* delims=/" %%a in ("%line%") do (
echo Got one token: %%a
set line=%%b
)
if not "%line%" == "" goto :processToken
goto :eof
This reads a file line-by-line, removing leading spaces (thanks, jeb).
sets then the
linevariable to the line just read andcalls a subroutine that does something with the line
is the start of the subroutine mentioned above.
will then split the line at
/, but stopping tokenization after the first token.will output that first token and
will set the
linevariable to the rest of the line.And if
lineisn’t yet empty (i.e. all tokens processed), it returns to the start, continuing with the rest of the line.