Batch Script Syntax
Turn off echo
Usually, the first line of a batch file consists of:
@echo offThe command echo off turns off the display for the whole script, except for the "echo off" command itself. The @ sign in front makes the command apply to itself as well.
Documentation
Very often batch files also contains lines that start with the Rem command.
This is a way to enter comments and documentation.
Rem This is a documentation lineFirst Batch Script Program
Open Notepad and enter the following example:
@echo off
Rem List and save to file all the files in the directory Program files
dir "C:\Program Files" > C:\lists.txt
echo "The program has completed"The code does the following:
- Uses the
echo offcommand to ensure that the commands are not shown when the code is executed. - The
Remcommand is used to add a comment to say what exactly this batch file does. - The
dircommand is used to take the contents of the locationC:\Program Files. - The
>command is used to redirect the output to the fileC:\lists.txt. - Finally, the echo command is used to tell the user that the operation is completed.