@echo off :: This batch file demonstrates a technique to process optional parameters. :: The batch file args may be presented in any order. :: By doing the 'if' twice, I think the code is much easier to read than :: other styles which jump around a lot. :: In this variation, processing of each arg is done by a "subroutine". :: fred fisher :: ffisher@nvidia.com :: name fredargsub.bat :: parameters: :: -1 A simple switch (using no following arguments) :: -2 The name2 parms (using 1 following argument) :: -3 The name3 parms (using 2 following arguments) :: you may have any number of parameters :: init variables if "%1" == "sub" goto %2 goto loop :shift3loop shift :shift2loop shift :shiftloop shift :loop :: here test for expected args if "%1"=="-1" call fredargsub sub sub1 yes if "%1"=="-1" goto shiftloop if "%1"=="-2" call fredargsub sub sub2 %2 if "%1"=="-2" goto shift2loop if "%1"=="-3" call fredargsub sub sub3 %2 %3 if "%1"=="-3" goto shift3loop if "%1" == "" goto done echo Usage error echo ???UNRECOGNIZED ARG '%1' goto done :sub1 echo process '-1' command goto done :sub2 echo process '-2' command using '%3' goto done :sub3 echo process '-3' command using '%3' and '%4' goto done :done