batch-file Batch file command line arguments Batch files with more than 9 arguments


When more than 9 arguments are supplied, the shift [/n] command can be used, where /n means start at the nth argument, n is between zero and eight.

Looping through arguments:

set /a "i+=1"
set arg!i!=%~1
call echo arg!i! = %%arg!i!%%
goto :args

Note, in the above example delayed expansion variable i is used to assign argument values to variables array. The call command allows to display such variable values inside the loop.

Counting arguments:

for %%i in (%*) do (set /a ArgCount+=1)
echo %ArgCount%

Set a variable to n'th argument:

set i=5
call set "path%i%=%%~i"