# How to create batch file on Windows

### What is a batch file or .bat file

A batch file is a text file that contains a sequence of commands for executing in a computer operating system. It batches multiple executables commands into a single file and executes all at once. A batch file is usually created for command sequences for which a user has a repeated need. Commonly needed batch files are often delivered as part of an operating system. You initiate the sequence of commands in the batch file by simply entering the name of the batch file on a command line.

### Why you need a batch file.

why should you keep the commands in a batch file?. A batch file saves the time, otherwise, would be invested in typing the same commands again and again. For example, you can schedule your Windows OS to shut down after a specific amount of time using the command prompt. If you have created a batch file for the shutdown operation, you’ll only have to double-click to run it, like you normally open applications, and your Windows will shut down after the time you have already set.

### How to create a batch file.

You can create a batch file using the steps below. If you are more comfortable with Microsoft Windows, you can use any text editor such as Notepad or WordPad to create your batch files. The file extension must end with .bat. In the example below, we use the Windows Notepad to create a batch file.

Open a new notepad file. You can also use any similar text file editor, like Notepad++.
Once Notepad is open, type the following lines.

```   @echo off
echo Hello this a test batch file
pause
dir c:\windows
pause```

Save the text file with the extension .bat instead of .txt.
To run your batch file, double click the BAT file you just created. Above program will execute the following cmd.

### Some basic batch commands.

Some of the more important ones include:

ECHO  Displays text on the screen
@ECHO OFF – Hides the text that is normally output
START   Run a file with its default application
REM   Inserts a comment line in the program
DEL   Deletes a file or files
COPY  Copy a file or files
MKDIR/RMDIR – Create and remove directories
FOR/IN/DO   This command lets you specify files.
TITLE   Edit the title of the window. [1]
XCOPY   Allows you to copy files with extra options

Anwar Yakkiparamban

Anwar Yakkiparamban is the founder of Lauyou Learning. Prior to Lauyou learning, Anwar worked at ARD Engineering & Development, Qatar. He holds bachelor degree in Electronics and Communication Engineering from Govt. Engineering College Idukki.