What is a Batch File? - Examples & Basics

Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

In this lesson, you will discover and understand a powerful computer processing tool: The batch file. You will also be shown some useful examples for batch files, including a process for backing up the valuable data stored on your computer.

What is a batch file?

When you hear the word batch you may think of cookies. But what about a batch file? No, it isn't a plate of cookies stored in a filing cabinet. It is a simple but powerful tool used in computing and information systems.

Batch files are not scary. They are not overly complicated (unless you prefer that sort of thing); though they can be very powerful and very complex, they can also be as simple as a plate of fresh chocolate chip cookies.

Batch files: Overview and Examples

A batch file is a text file that carries out one or more computer tasks in a given order; it is like a mini computer program, but without all the squiggly lines and confusing characters. To return to the analogy of the cookies, it would take many hours to mix and bake four thousand cookies. However, the steps are routine and defined (quantities of ingredients, mixing method, and baking temperatures/times). Think of a batch file as the combination of the recipe card and the baking process. This information is listed out in a simple text format, saved into the computer, and run. Voila! Cookies!

Unfortunately, we won't be learning how to automate our grandmother's recipe; instead we will focus on the basics of a batch file and how the computer performs tasks.

Batch files are used across the computer industry, both by professionals and everyday computer users. Any task that can be run on a computer, from creating/moving/renaming folders and files to starting programs and features. They are excellent tools for automating time-consuming system tasks; it would take a great deal of time to copy a file from one folder and paste it into several other folders, or to delete extra or temporary folders on the system. An organization may have to copy a specific file out to all users and manually doing so could be prohibitive; instead, by using a simple batch file, the process is completed in seconds.

Although batch files can be simple, they can also be used in organizations to carry out a series of repetitive and/or time-consuming tasks.

Just as an Excel file may have an extension (the letters after the period in a file name) of .xlsx or .xls, batch files are created with special extensions so the computer knows what to do with the file. The most common extension used is .bat, although .cmd is also used. This extension tells the computer what to do with the file.

Example 1: A very simple file

1) Open Notepad (or a plain text editor) on your computer. Do not use Word or any other word processing software, as it will add extra or hidden characters to the file.

2) Enter the following:

@echo off

md C:\sourcefolder

md C:\destinationfolder

3) Save the file as myfirstbatch.bat

4) Navigate to the desktop and double-click the file

5) There will be a brief flash as the command prompt opens and closes. Your new files should be in the folder

Note: The @echo off command will hide the command prompt (that little black screen that sometimes pops up on computers. For simple tasks, we don't need to see that screen. However, corporate computer systems may run huge batch files and they want the end users (or support staff) to see the commands that are being run by the system.

Example 2: Backup your files (photos, music, videos)

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account