Batch file introduction, you should know

A batch file is a text file that contains a sequence of commands for a computer operating system. The batch script file has a bundle or package of a set of commands that is the reason it is called the batch file. The extension of the batch script file is .bat or .cmd.

Sometimes in windows OS, we need to run a lot of commands on command prompt window for any require setup or configuration. It is a time consuming and boring process but we can make it easy with the help of batch files.

How to create Batch files

The way of creating a batch file is simple as you can think. Below I am mentioning the steps to create a batch file:

  • Open the notepad.
  • Create a new file in notepad.
  • Write your require commands in the newly created file.
  • Save the new file with the .bat extension.

How to Execute Batch Files

  • Open the command prompt window.
  • Go to the location where the .bat file is stored.
  • Execute the .bat file on the command prompt.

How to Modifying Batch File

  • You can easily edit the batch file as similar to the text file.
  • Open the batch script file using any editor (notepad).
  • Bach file should have write permission.
  • Edit the batch file and save it.
If you want to learn more about the c language, here 10 Free days C video course for you.

C tutorial

Sample example to create and execute a batch script

As I have described in the above statements that first need to create a new file in notepad or notepad++.


Now save newly created file with .bat extension.

create batch file

After saving with .bat extension newly created file become a batch file.

batch file overview

Now open the newly created batch script file using any editor (notepad) and write your desire commands. I am writing echo commands to display the message. See the below two images.

modified batch file


write command in batch file

After writing the commands save the batch script file and run it on the command prompt window.

Some of the Important features of Batch Script

  • We can create a variable.
  • We can use a conditional statement(for, if, while, switch).
  • Using Batch script we can read inputs from users.
  • The batch script supports advanced features such as Functions and Arrays.
  • It also supports regular expressions.
  • We can also use line continuation.


Leave a Reply