添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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.

The %%b is pure misinformation. Only %%a is assigned in the loop and line=%%b would just assign "%b" to "line" – GrayFace Apr 7 at 14:51