What are Batch (.bat) Files?

In the DOS environment, batch files are the list of command line instructions batched together. The purpose of batch file is to run a set of commands in sequence. Creating a batch file is very easy and doesn't require any programming skills.

Some Simple Batch Commands 


CallCall command can be used to call another batch file inside the current file.
call c:\test2.bat
 
Echo
Echo command is used for displaying information and commands on the screen or prevent them from being displayed.
 Echo on  and @Echo off are the two supplementary commands created out of Echo to turn ON and OFF the information display

For
If you need to select a specific set of files and run a command on each of them, FOR is used
for (variable) in (set of files) do (command)

Let's see how it works:
We need to delete all pictures (jpg files) from a directory in the system. Let's write a batch file which does that selective deletion.
for %%F in (*.jpg) do del "%%F"
Explanation:

  1. We are storing the value of every file ending in .jpg in the current directory to a variable '%%F' 
  2. Then, we ask the DEL command to delete all the values stored in the variable '%%F'.Pretty simple, huh?

If
This is used for executing a command based on a condition. IF must include an ELSE statement which says what happens if the condition is not met.
Let's see how it works:
if exist c:\test.txt (copy c:\test.txt d:\backup) else echo test.txt does not exist
Explanation:
If the 'test.txt' file exists, it will be copied to d:\backup. If it doesn't exist, a message test.txt does not exist" will be displayed.


REM
This is how commenting is done in batch file. Commenting serves as a help explanation about the file.
@echo off
rem This batch file aims
rem to copy files between directories
if exist c:\test.txt (copy c:\test.txt d:\backup) else echo test.txt does not exist


Crippled References:

See wiki for the list of command line references.
See help on how to create Microsoft XP batc files