How to loop through comma separated string in batch?

后端 未结 4 533
[愿得一人]
[愿得一人] 2020-12-09 15:46

Windows

Based on the post (dos batch iterate through a delimited string), I wrote a script below but not working as expected.

Goal: Given st

4条回答
  •  一生所求
    2020-12-09 16:18

    Looks like it needed the "tokens" keyword...

    @echo off
    set themes=Sun,Granite,Twilight
    
    call :parse "%themes%"
    goto :end
    
    :parse
    setlocal
    set list=%1
    
    for /F "delims=, tokens=1*" %%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
    goto :end
    
    :getLineNumber
    setlocal
    echo file name is %1
    set filename=%1
    endlocal 
    
    :end
    

提交回复
热议问题