What is a Batch file?

A Batch file is a list of commands “batched” together in one file. They are not programs. When a batch file is run, a shell program such as command.com or cmd.exe reads the file and executes it’s instructions. They have the extension .bat, .sys, .cfg, .inf – these are just different kinds of batch files. One of the most important batch files in Dos and Windows is Autoexec.bat

You will see a number of these files in the c:\WINDOWS or C:\WINNT folder. Batch files do not have to be compiled and do not contain any compiled codes, so these files can be opened and edited. Batch files form a major portion of the Windows Operating system. Batch files are used by System Admins to automate many important day-to-day tasks.

How to create a Batch file?

Open Notepad and type in this text (or just copy and paste it in there)

@ECHO OFF
REM: I am creating a batch file
ECHO I have a good computer!
ECHO
PAUSE
ECHO Today’s date is: &Date
PAUSE
CLS
EXIT

If you do not wish to use Notepad, you can create a Batch file directly from your computers console by typing in the following commands:

COPY CON ABC.BAT
@ ECHO OFF
ECHO Welcome to my world !
ECHO
PAUSE
CLS
^Z

If you are using this method, the most important thing is to start writing your batch file with the “Copy Con” command (which basically means “copy from Console”. The last line should contain ^Z (Control+Z), which saves your batch file.

Also, remember, when you are creating a batchfile using a text editor, you can only use Notepad. Do not use Word or Wordpad. Then, if you want to run your batch file, just double click on it.

Here’s another batch file that will clear all the cookies from your computer:

@ ECHO OFF
REM This is a batch file to clear all the cookies from your computer
ECHO
DELTREE /y c:\windows\cookies\*.*
DELTREE /y c:\windows\tempor~1\*.*
CLS
ECHO All cookies have been removed from your computer!
PAUSE
CLS
EXIT

Any valid DOS command can be used in a batch file.

Types of Batch files:

INI, *.ini : These are Initalization file. These set the default variables for the system and programs.

CFG, *.cfg : These are configuration files.

SYS, *.sys : These are system files and can sometimes be edited. They mostly contain compiled machine code in new versions.

COM, *.com :
They are Command files. These are the executable files for all the DOS commands. In early versions there was a separate file for each command. Now, most are inside COMMAND.COM.

NT, *.nt : These are Batch files used by the NT operating systems.

CDM, *.cmd :
Batch files used in NT operating systems.