Batch-Script - Iterate through arguments

前端 未结 6 678
暖寄归人
暖寄归人 2020-12-08 18:49

I have a batch-script with multiple arguments. I am reading the total count of them and then run a for loop like this:

@echo off
setlocal enabledelayedexpans         


        
6条回答
  •  感动是毒
    2020-12-08 19:47

    here's one way to access the second (e.g.) argument (this can be put in for /l loop):

    @echo off
    setlocal enableDelayedExpansion
    set /a counter=2
    call echo %%!counter!
    endlocal
    

    so:

    setlocal enableDelayedExpansion
    set /a counter=0
    for /l %%x in (1, 1, %argCount%) do (
     set /a counter=!counter!+1
     call echo %%!counter! 
    )
    endlocal
    

提交回复
热议问题