批处理文件FOR / F令牌 [英] Batch file FOR /f tokens
问题描述
任何人都可以请解释下code究竟是如何工作的,一行行。我真的失去了。我一直在努力学习如何使用FOR命令,但我不明白这一点。
关闭@echoFOR / F令牌= * delims =%%的(MYFILE)f执行(
集线= %%˚F
拨打:processToken
)
GOTO:EOF:processToken FOR / F令牌= 1 * delims = /%%一中(%线%)做(
回声得到了一个道理:一个%%
集线= %% b
)
如果不是%线%==GOTO:processToken
GOTO:EOF
FOR / F令牌= * delims =%%的(MYFILE)f执行
这读取文件中的行由行,删除前导空格(感谢,杰布)。
集线= %%˚F
设定则行
变量行仅读和
电话:procesToken
调用一个子程序做一些事行
:processToken
是上述子例程的开始。
FOR / F令牌= 1 * delims = /%%一中(%线%)做
然后
将在 /
分割线,但停药符号化的第一个标记之后。
回声得到了一个道理:一个%%
将输出,首先令牌以及
集线= %% b
将设置行
变量行的其余部分。
如果不是%线%==GOTO:processToken
如果行
不是空(即所有标记处理),则返回到开始,与行的其余部分继续。
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
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.
这篇关于批处理文件FOR / F令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!