Batch-Script - Iterate through arguments

前端 未结 6 677
暖寄归人
暖寄归人 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:49

    For simple iteration can't we just check for additional arguments with "shift /1" at the end of the code and loop back? This will handle more than 10 arguments, upper limit not tested.

    :loop
    
    :: Your code using %1
    echo %1
    
    :: Check for further batch arguments.     
    shift /1
    IF [%1]==[] (
    goto end
    ) ELSE (
    goto loop
    )
    
    :end
    pause
    

提交回复
热议问题