Skip to content

Batch Script Syntax

How to use essential batch script commands like @echo off, Rem for comments, and basic syntax to create and document Windows batch files."

Batch Script Syntax

Turn off echo

Usually, the first line of a batch file consists of:

@echo off

The 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 line

First Batch Script Program

Open Notepad and enter the following example:

FirstExample.batbatch
@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 off command to ensure that the commands are not shown when the code is executed.
  • The Rem command is used to add a comment to say what exactly this batch file does.
  • The dir command is used to take the contents of the location C:\Program Files.
  • The > command is used to redirect the output to the file C:\lists.txt.
  • Finally, the echo command is used to tell the user that the operation is completed.
Navigation