@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. :: fred fisher :: ffisher@nvidia.com :: name fredarg.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 set name1=no set name2= set name3= goto loop :shift3loop shift :shift2loop shift :shiftloop shift :loop :: here test for expected args if "%1"=="-1" set name1=yes if "%1"=="-1" goto shiftloop if "%1"=="-2" set name2=%2 if "%1"=="-2" goto shift2loop if "%1"=="-3" set name3=%2 %3 if "%1"=="-3" goto shift3loop if "%1" == "" goto print echo Usage error echo UNRECOGNIZED ARG '%1' goto done :print echo name1 = '%name1%' echo name2 = '%name2%' echo name3 = '%name3%' :: process args here... :done