视窗
根据帖子(dos batch iterate through a delimited string),我在下面编写了一个脚本,但没有按预期工作。
目标:给定字符串“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