Writing a batch file
1 January 2000 by Snakefoot | Comment » | Trackback OffA batch file is a small script that can be used to perform several commands, or simplify a complex command which requires many parameters. One executes the batch file like one executes a normal exe-file.
To write a batch file, one has to use a simple text-editor and when saving the script then give it the proper file extension ".BAT". When writing the batch file one can make use of different builtin commands:
Examples of possible ways to use batch files:
Tricks one can use to enhance a batch file:
To write a batch file, one has to use a simple text-editor and when saving the script then give it the proper file extension ".BAT". When writing the batch file one can make use of different builtin commands:
| Keyword | Functionality |
|---|---|
| ECHO | Displays a text string |
| REM | Used to comment out a command or make a remark |
| SET | Saves a value in an environment variables |
| GOTO | Jumps to a :LABEL, which can be used to make loops or function calling |
| IF | Allows conditional behavior |
| CALL | Used for calling other batch files |
| FOR | Performs a command on a collection of items |
| ERRORLEVEL | Contains the returncode of an excuted program |
| %1-%9 | When calling a batch one can provide parameters, which the batch file can access as environment variables |
| PAUSE | Stops the execution of the batch file until the user presses a key on the keyboard |
Updated: 22 September 2007