Windows
根据这篇帖子(dos批处理迭代遍历分隔字符串), 我编写了下面的脚本,但是它并不像预期的那样工作。
目标: 给定字符串 "Sun,Granite,Twilight",我想要循环获取每个主题值,以便我可以对该值进行一些处理。
当前输出不正确:
list = "Sun,Granite,Twilight"
file name is "Sun Granite Twilight"
第一次迭代应该是:
list = "Sun,Granite,Twilight"
file name is "Sun"
第二次迭代应该是“文件名是“Granite”,依此类推。我错在哪里了?
代码:set themes=Sun,Granite,Twilight
call :parse "%themes%"
goto :end
:parse
setlocal
set list=%1
echo list = %list%
for /F "delims=," %%f in ("%list%") do (
rem if the item exist
if not "%%f" == "" call :getLineNumber %%f
rem if next item exist
if not "%%g" == "" call :parse "%%g"
)
endlocal
:getLineNumber
setlocal
echo file name is %1
set filename=%1
endlocal
:end
for %%a in ("one" "two" "three and four") do echo %%a
将输出one\ntwo\three and four
。 - rocketmonkeys