@echo off :: The batch file I wanted to write required a number of optional parameters in :: any sequence, the only way I could figure out which ones were which was to :: include a label before the parameter. The following batch file shows how :: this is implemented: :: Simon Richardson :: simonr@uklinux.net :: name: ARGUMENTS.BAT :: parameters: :: -c The cname parm :: -s The sname parm :: -u The uname parm :: note a maximum of 3 parameters :initial if "%1"=="-c" goto lcname if "%1"=="-s" goto lsname if "%1"=="-u" goto luname if "%1"=="" goto print goto error :lcname shift set cname=%1 goto lreturn :lsname shift set sname=%1 goto lreturn :luname shift set uname=%1 :lreturn shift call arguments.bat %1 %2 %3 %4 %5 %6 goto done :error echo %0 usage error goto done :print echo cname = %cname% echo sname = %sname% echo uname = %uname% :done :: Note from Eric Phelps :: :: In addition to solving Simon's problem of handling :: arguments in any order, the above batch file demonstrates :: recursiveness (getting a program to re-run itself) :: and subroutines (not obvious, but the way it is implemented :: above by jumping to a label and then leaving is as close :: as we can come in the batch world). See another example of :: subroutines here: :: http://www.ericphelps.com/batch/samples/subsdemo.bat.txt :: The down side of these techniques is that they require :: the batch file to be able to find itself. Notice the "call" :: line in the "lreturn" code section. It has to have the name :: (and preferably the path too) of the batch file. This means :: if you rename the batch file, you must recode that line. :: This is no problem if you write the batch file for yourself. :: You'll know the name and path. But -- if you give the batch :: file to someone else (like we are doing here!), they might :: give it a different name and put it who-knows-where and call :: it who-knows-how. So... You might need to modify the code a :: bit and break Simon's demonstrated "pure" method of :: recursiveness and subroutines. Instead of having the batch :: file call itself, just have it jump to the starting point :: again. This isn't always possible, but it can be done here. :: Just change the "lreturn" section so it only contains these :: two lines: :: shift :: goto initial :: And just for completeness, stick a "goto done" at the end :: of the "print" code section. :: :: If you want to modify the code so it can accept any :: number of arguments (and ignore everything it wasn't :: expecting), change the "initial" code section so it only :: contains these lines: :: if "%1"=="-c" goto lcname :: if "%1"=="-s" goto lsname :: if "%1"=="-u" goto luname :: if "%1"=="" goto print :: shift :: goto initial :: Of course, if you do that, nothing will ever call the :: error code. So you could either eliminate the entire "error" :: code section or put another test for no arguments ahead :: of the "initial" code section.