Writing a batch file
A 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:
Keyword | Functionality |
---|---|
[ECHO](/article/echo-output.html) | Displays a text string |
REM | Used to comment out a command or make a remark |
[SET](/article/environment-variables.html) | 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](/article/for-operation-files.html) | Performs a command on a collection of items |
[ERRORLEVEL](/article/errorlevel-return-code.html) | Contains the returncode of an excuted program |
[%1-%9](/article/batch-file-input-parameters.html) | 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 |
Examples of possible ways to use batch files:
- Enhanced dir command
- Enhanced mem command
- Easy compressing and extracting using batch files
- Find file utility
Tricks one can use to enhance a batch file: