Both answers are correct, but I'm a little different. You might want to consider a couple of things ...
Run the package with:
SetLocal
and complete it with
EndLocal
This will cause all of your “SETs” to be valid only during the current session and not leave the left vars around the name “FileName1” or any other variables that you set during the run, which may interfere with the next run of the batch file. So you can do something like:
IF "%1"=="" SET FileName1=c:\file1.txt
Another trick is that if you provide only 1 or 2 parameters, use the SHIFT command to move them, so the one you are looking for is ALWAYS on% 1 ...
For example, process the first parameter, slide them, and then do it again. This way you are not hard coding% 1,% 2,% 3, etc.
A Windows batch processor is much more efficient than people giving him credit .. I did some crazy things with it, including yesterday’s calculation, even during the month and year, including Leap Year, and localization, etc.
If you really want to be creative, you can call functions in a batch processor ... But this is really for another discussion ... :)
Oh, and do not name your batch files .bat .. They are now .cmd .. heh ..
Hope this helps.
LarryF Apr 08 '09 at 19:17 2009-04-08 19:17
source share