Batch file programming is the native programming offered by the Microsoft Windows Operating System. Batch file is created using any text editors like notepad, WordPad etc, which comprises of a sequence of built-in commands used to perform some often done tasks like copying a series of files of same type or of different type, deleting files, configuring your network and even for creating a batch VIRUS.

Whenever a Batch program is executed, it is interpreted line-by-line by the CLI (Command Line Interpreter) command.com or the cmd.exe. Batch file is really helpful in automating tedious tasks and for maintaining system logs. The commands used while creating a batch file are not case sensitive, in the sense that it may accept both small and upper case letters.

There are two different modes that are supported by the Disk Operating System, they are,

  • Interactive Mode.
  • Batch Mode (Silent Mode).

Interactive mode:

In interactive mode, when a command is executed, it interacts with the user for input and depending upon the input supplied by the user, the further processes are carried out. For example, let’s take the ‘del’ command.

The ‘del’ command is used for deleting files that reside inside a directory. Now I am going to delete all the files inside a folder named ‘a’, and when I executed the following command, it is interacting with me prompting “Are you sure (Y/N)?”, confirming the deletion operation, and depending upon my input, it decides what to do. If I hit ‘Y’ then it will delete the files specified, else if I hit ‘N’ then it won’t delete.
C:>del a
C:a*, Are you sure (Y/N)? y

Batch Mode:

Batch mode can also be referred as ‘Silent mode’ or ‘Quiet Mode’, and this is mere opposite to the interactive mode. The command that operates at batch mode will never interact with the user at any instance, instead it will take care of every operation by itself.

For example, I am going to explain this by using the same ‘del’ command. There is a switch available for the ‘del’ command, which makes the command to operate at silent mode, and that switch is ‘/Q’
C:>del /Q a
C:>

In this case, the command is not at all interacting with me, whether to delete those file or not.

How to create a Batch Program:

Batch programs can be written using any of the text editors such as notepad, wordpad and so on, but notepad is the most often used text editor in such cases. Like any other programing languages, lets start our first program with the ‘Hello World’ program.

1. Open up a notepad and type the following.
@echo off
Echo Hello World
pause
2. Save the file with any name you wish, but make sure that you save the file extension with .bat.
3.Now just double click the file to execute your commands.
Let us now understand the above commands

“Echo” command is used to print text on screen, but when you type just Echo, it tells us wether echo is on or off.It is always a good practice to turn off echo, otherwise it will also prints prompt like C:> etc. Hence we used the command @echo off.

Now echo Hello World will display “Hello World” on the screen, the pause command is used to hold the screen for user interaction, if it was not used the screen would then immediately terminate after Hello World was displayed.

Leave a Reply