Lonny was once a software programmer (video game industry). He now teaches psychology at King University. He has a bachelor's in IT and a PhD in psychology.
How to Create a Batch File
What is a Batch File?
Unless you grew up in the days before the Windows operating system, you may not have heard of a batch file. So, what is a batch file anyway?
Simply put, a batch file is a simple text file that acts more like a computer program than a text document. These files are usually named so they end with the file extension .bat. That's important, because the operating system uses that file extension to figure out if this is a batch file. For example, if you name it batch.bat, the computer will execute it as a batch file. But if you name it batch.txt, the computer will open it in text mode instead.
What Does a Batch File Do?
A batch file automates computer tasks for you, so you don't have to type in the instructions every time. Where do you type in instructions in Windows, you ask? Good question. You normally type the instructions in something called the Windows Command Prompt (it's a little black window that lets you type text instructions in it). Super users know how to do amazing tricks with a computer - often using a Command Prompt. If you've ever had a tech clean your temporary folders, for instance, he or she probably used a Command Prompt to type stuff in and clean everything in your temporary folders to make your system run faster. The same tech may even have used a batch file to avoid typing in all those commands.
Here's an example of the Command Prompt in Windows 10:
![]() |
How Do I Create a Batch File?
The easiest way to create a batch file is to perform the following steps:
- Right click on your computer desktop
- In the context menu that pops up, choose New, then choose Text Document
- Rename the new file as name.bat (but insert your desired name where 'name' is)
Important: Windows automatically adds the file extension .txt, so make sure you change it to .bat. Windows will warn you not to change the file extension, but you can ignore that. Now you can edit this like any old text file. Since the file extension isn't .txt though, you will need to right click it each time, and choose Edit whenever you want to edit the text in your batch file. Otherwise, if you double click it (or right click it and choose Open), it will execute as a batch file (more like a program) instead of letting you edit it.
Can We Make a Simple Batch File?
Sure, let's make a super simple batch file to make sure you have the hang of it. Follow the above steps under How Do I Create a Batch File to create a file on your desktop called study.bat. Now right click it and choose Edit to open it in Notepad. Type in the following three lines of text:
![]() |
Now, save the file and close it. When you're done, double click the file study.bat on your desktop to execute it. What happened? This batch file is super simple. The first line tells the computer not to display the lines in the batch file unless told to (otherwise it will). The second line changes the background color to dark blue and the foreground color to light yellow. The third line prints out 'I wrote this!' The last line pauses until the user presses a key. That's it!
Lesson Summary
A batch file is a simple text file that can automatically perform tasks, instead of having to type instructions at the Command Prompt every time you need to do them. It uses a special file extension. To create one, just make a text file and rename it with the file extension .bat. It's easy to make batch files, and they can save time and typing.
To unlock this lesson you must be a Study.com Member.
Create your account
Register to view this lesson
Unlock Your Education
See for yourself why 30 million people use Study.com
Become a Study.com member and start learning now.
Become a MemberAlready a member? Log In
BackResources created by teachers for teachers
I would definitely recommend Study.com to my colleagues. It’s like a teacher waved a magic wand and did the work for me. I feel like it’s a lifeline.