Using batch file input parameters
1 January 2001 by Snakefoot | Comment » | Trackback OffMany programs are able to handle input parameters, which one can specify when launching the program from the command line. This usually makes the program more generic and a better tool to work with (Ex. giving "a:" as parameter):
To check if a parameter is given:
Note there also exists the input parameter %0, which is actually the batch-filename it self.
Note one can also use the SHIFT command incase the input parameter doesn't have to be in a certain order. SHIFT moves the parameter one to the left so %1 disappears, %2 becomes %1, %3 becomes %2 and etc. This behavior can be useful when having a batch file which receives an undefined order or amount of parameters.
When starting a batch file, then one can also specify input parameters. The parameters can be accessed by the batch file like environment variables, and have the values %1 to %9.Format a:
To check if a parameter is given:
More Info MS KB Q71247IF "%1"!="" ECHO Got %1
Note there also exists the input parameter %0, which is actually the batch-filename it self.
Note one can also use the SHIFT command incase the input parameter doesn't have to be in a certain order. SHIFT moves the parameter one to the left so %1 disappears, %2 becomes %1, %3 becomes %2 and etc. This behavior can be useful when having a batch file which receives an undefined order or amount of parameters.
:PARSELOOP
IF "%1"=="" GOTO ENDPARSE
IF "%1"=="DEBUG" SET BUILD=DEBUG
IF "%1"=="RELEASE" SET BUILD=RELEASE
SHIFT
GOTO PARSELOOP
:ENDPARSE
Updated: 23 September 2007
Comment by Edwin Duncan-Dunlop - 22 January 2009 @ 19:33 Reply
I have a list.txt file of filenames,which I want to use 1 at a time as parameters in a batch file.
I thought I could use