Batch file FOR /f tokens

前端 未结 1 1563
醉酒成梦
醉酒成梦 2021-01-31 18:07

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 thi

相关标签:
1条回答
  • 2021-01-31 18:38
    for /f "tokens=* delims= " %%f in (myfile) do
    

    This reads a file line-by-line, removing leading spaces (thanks, jeb).

    set line=%%f
    

    sets then the line variable to the line just read and

    call :procesToken
    

    calls a subroutine that does something with the line

    :processToken
    

    is the start of the subroutine mentioned above.

    for /f "tokens=1* delims=/" %%a in ("%line%") do
    

    will then split the line at /, but stopping tokenization after the first token.

    echo Got one token: %%a
    

    will output that first token and

    set line=%%b
    

    will set the line variable to the rest of the line.

    if not "%line%" == "" goto :processToken
    

    And if line isn't yet empty (i.e. all tokens processed), it returns to the start, continuing with the rest of the line.

    0 讨论(0)
提交回复
热议问题