A BAT file is known as a batch file runs with DOS and all versions of Windows, under cmd.exe. It consists of a series of line commands in plain text to be executed by the command-line interpreter to perform different tasks, such as running maintenance utilities within Windows or starting typical programs. A batch file may include any command that can be accepted by the interpreter interactively and use the structure of code that enable conditional branching and looping as written within the batch file.
BAT file format
A BAT file format is simply a script incorporated to automate command sequences which are repetitive in nature. The term “batch” is used for batch processing, It can be considered as “non-interactive execution”. Therefore a batch file may not process a batch of multiple data. In the old Disk Operating System (DOS), the batch file was run under the command line interface by typing the filename and the extension .bat. The earlier Microsoft graphical interface based operating system such as Microsoft Windows was dependent on DOS. The users had to use DOS to perform typical operations like repair, optimize or re-installing Windows. Later on the Microsoft introduced Windows NT which was not dependent on DOS operating system. Therefore, the batch files can be run by using Command Prompt or cmd.exe in the modern days Microsoft operating systems.
Batch file parameters
Command prompt supports a number of special variables such as %0, %1 to %9 in order to refer to the name and path of the batch job and the nine calling parameters from within the batch job. Non-existent parameters are replaced by a string having zero-length. Although, they can be used similar to environment variables, but are not saved in the environment. Microsoft and IBM refer to these variables as replacement parameters, While Novell, Digital Research, and Caldera introduced the term replacement variables for them.
Here are some useful Batch file commands:
This batch command shows the version of MS-DOS you are using.
This is a batch command that associates an extension with a file type (FTYPE), displays existing associations, or deletes an association.
This batch command helps in making changes to a different directory, or displays the current directory.
This batch command clears the screen.
This batch command is used for copying files from one location to the other.
This batch command deletes files and not directories.
This batch command lists the contents of a directory.
This batch command help to find the system date.
This batch command displays messages, or turns command echoing on or off.
This batch command exits the DOS console.
This batch command creates a new directory in the current location.
This batch command moves files or directories between directories.
This batch command displays or sets the path variable.
This batch command prompts the user and waits for a line of input to be entered.
This batch command can be used to change or reset the cmd.exe prompt.
This batch command removes directories, but the directories need to be empty before they can be removed.
Renames files and directories
This batch command is used for remarks in batch files, preventing the content of the remark from being executed.
This batch command starts a program in new window, or opens a document.
This batch command sets or displays the time.
This batch command prints the content of a file or files to the output.
This batch command displays the volume labels.
Displays or sets the attributes of the files in the curret directory
This batch command checks the disk for any problems.
This batch command provides a list of options to the user.
This batch command invokes another instance of command prompt.
This batch command compares 2 files based on the file size.
This batch command converts a volume from FAT16 or FAT32 file system to NTFS file system.
This batch command shows all installed device drivers and their properties.
This batch command extracts files from compressed .cab cabinet files.
This batch command searches for a string in files or input, outputting matching lines.
This batch command formats a disk to use Windows-supported file system such as FAT, FAT32 or NTFS, thereby overwriting the previous content of the disk.
This batch command shows the list of Windows-supplied commands.
This batch command displays Windows IP Configuration. Shows configuration by connection and the name of that connection.
This batch command adds, sets or removes a disk label.
This batch command displays the contents of a file or files, one screen at a time.
Provides various network services, depending on the command used.
This batch command sends ICMP/IP “echo” packets over the network to the designated address.
This batch command shuts down a computer, or logs off the current user.
This batch command takes the input from a source file and sorts its contents alphabetically, from A to Z or Z to A. It prints the output on the console.
This batch command assigns a drive letter to a local folder, displays current assignments, or removes an assignment.
This batch command shows configuration of a computer and its operating system.
This batch command ends one or more tasks.
This batch command lists tasks, including task name and process id (PID).
This batch command copies files and directories in a more advanced way.
This batch command displays a tree of all subdirectories of the current directory to any level of recursion or depth.
This batch command lists the actual differences between two files.
This batch command shows and configures the properties of disk partitions.
This batch command sets the title displayed in the console window.
Displays the list of environment variables on the current system.
BAT file example
Batch scripts are usually saved as simple text files; containing commands that get executed in a sequence. These files are saved with .bat extension; recognized and executed by using Command Interpreter software. This software is natively available in Microsoft Windows with name cmd.exe.
Here is a sample Batch Script which deletes all files in the current directory:
:: Deletes All files in the Current Directory With Prompts and Warnings
::(Hidden, System, and Read-Only Files are Not Affected)
:: @ECHO OFF
DEL . DR