Techniques for using built-in command line parameter modifiers to change the values of parameters passed in the command line for specific programming purposes.
Batch file programming is a very useful way to automate small, repetitive, tasks. For those who are new to creating batch files, the Windows Command Line Programming tutorial is a good starting place to read about the basics of batch file programming.
Batch file parameters are arguments that are passed to batch files just like passing any parameters to a command accessed in the command line (be it MS-DOS, Windows XP, or a MS-DOS compatible command line interface). Rather than just taking in the parameters as the user (or batch file command script) specified them, the Windows command line allows a number of modifiers to be applied which change the expansion of the parameters.
Parameter expansion is the term used to specify what the command processor (Windows or MS-DOS command line environment) does when it retrieves the parameter accessed by one of the built-in variables %0-%9.
The most commonly used modifiers are:
These can all be combined together in a variety of ways.
The modifiers above can also be combined to generate specific variations of the parameters passed on the command line, which include complex information. One of the most useful is to retrieve a directory listing style output line with the file name, date and time, attributes and size. For example:
The would lead to output such as:
The information can then be passed to the FOR command to be tokenized. This uses a modified version of the technique explained in the article discussing Using FOR Command to Parse Files.
Other combinations include building a complete fully qualified pathname from a parameter, by searching the PATH variable, which may have been set to a local environment (as explained in the Batch Programming Local Commands article. For example:
The above returns either the completely qualified pathname, or a blank value, making it easy to test for the existence of a specific command, executable application or batch script, using the IF command.