What a .bat file is and why you might create one
A .bat file is a plain text file that contains a list of commands Windows runs one after another, without you typing each one. The ".bat" stands for "batch" — it batches commands together. When you double-click a .bat file, Windows opens Command Prompt behind the scenes and executes every line in order.
People create .bat files to automate repetitive tasks: backing up folders, renaming dozens of files at once, starting multiple programs together, or running the same sequence of commands every day. Instead of typing the same ten commands manually each time, you write them once in a .bat file and run the whole sequence with a single click.
A .bat file is just text, so you can create one in Notepad. It runs only on Windows — Mac and Linux use different file types for the same purpose.
Key Takeaways
- A .bat file is a text file containing Windows commands that run automatically when you open it, letting you automate tasks without typing each command.
- You create a .bat file by writing commands in Notepad, saving it with a .bat extension instead of .txt, and then double-clicking it to run.
- Common commands include cd to change folders, copy to duplicate files, del to delete files, and the name of any program you want to launch.
- If a .bat file closes when ready after running, add pause as the last line so you can see what happened before the window shuts.
- Never run a .bat file from an unknown source, because it can delete files or change settings without asking permission first.
Creating a .bat file in Notepad
Open Notepad (search for "Notepad" in the Windows search bar, or press Windows key + R, type notepad, and press Enter). Type the commands you want to run, one per line. For example, a straightforward .bat file might look like this:
cd C:\Users\YourName\Documents copy report.txt backup_report.txt pause
This file changes to your Documents folder, makes a copy of a file called report.txt, and then pauses so you can see the results. Save the file by pressing Ctrl+S. In the "Save As" dialog, type a name with the .bat extension — for example, backup.bat. Make sure "Save as type" is set to "All Files" rather than "Text Documents (.txt)", or Windows will save it as a .txt file instead. Choose where to save it (your Desktop or Documents folder is fine for now) and click Save.
After you save, you should see the file appear in that folder with a different icon than a regular text file — usually a small gear or command prompt symbol. That icon tells you Windows recognizes it as a batch file.
Running your .bat file
Double-click the .bat file. A Command Prompt window opens and runs each line in order. If the commands work, you see the results. If something goes wrong, you see an error message. The window may close automatically when finished, or it may stay open — it depends on the last command in the file.
If the window closes too fast and you cannot read what happened, add the word pause on the last line of your .bat file. This tells Command Prompt to wait for you to press a key before closing. Edit the file by right-clicking it, choosing "Edit", making your change in Notepad, and saving. Then run it again.
You can also run a .bat file by right-clicking it and choosing "Run as administrator" if the commands need higher permissions — for example, if you are installing software or changing system settings. Windows will ask for confirmation before allowing it.
Common commands you can put in a .bat file
Here are commands that appear in most .bat files:
| Command | What it does | Example |
|---|---|---|
| cd | Changes to a different folder | cd C:\Users\YourName\Downloads |
| copy | Copies a file | copy oldname.txt newname.txt |
| del | Deletes a file | del unwanted.txt |
| dir | Lists all files in the current folder | dir |
| start | Opens a program or file | start notepad.exe |
| pause | Pauses and waits for you to press a key | pause |
| echo | Prints text to the screen | echo Backup complete |
You can combine these commands to do more complex work. For instance, you could write a .bat file that opens three programs at once, waits for you to use them, and then backs up a folder when you close the batch file.
Why you should be careful with .bat files from others
A .bat file can do anything Command Prompt can do, including delete files, change system settings, or read and run other programs. If someone sends you a .bat file or you read one from the internet, do not run it unless you understand what it does and trust the source. Open it in Notepad first and read the commands — if you see unfamiliar commands or anything that looks suspicious, do not run it.
Malware sometimes hides inside .bat files. A file that claims to do one thing (like clean your computer) might actually steal passwords or install unwanted software. The safest rule: only run .bat files you wrote yourself or that come from a source you know and trust.
Troubleshooting common problems
If your .bat file does not work, the most common reason is that the file path is wrong. When you use a command like copy or del, you need to tell it exactly where the file is. If the file is in a different folder than where the .bat file is running, the command fails. Use cd to change to the right folder first, or type the full path: copy C:\Users\YourName\Documents\report.txt C:\Users\YourName\Documents\backup.txt.
If you see "command not recognized" or a similar error, you may have misspelled a command or the program name. Check the spelling and try again. If a program name does not work, use the full path to the program file instead — for example, C:\Program Files\Notepad++\notepad++.exe instead of just notepad++.
If the .bat file runs but nothing seems to happen, add echo commands to print messages to the screen so you can see where it is in the process: echo Starting backup at the beginning, echo Backup complete at the end. This helps you figure out which part is working and which is not.
Frequently Asked Questions
Can I edit a .bat file after I create it?
Yes. Right-click the .bat file, choose "Edit", make your changes in Notepad, and save. The next time you run it, it will use the new commands. You can also open it in Notepad by dragging it onto a Notepad window.
What is the difference between a .bat file and a .cmd file?
.cmd files are newer and work the same way as .bat files on modern Windows. For most purposes they are interchangeable. Use .bat if you want the file to work on older Windows versions; use .cmd if you are on Windows 7 or newer and want slightly better compatibility with advanced features.
Can I schedule a .bat file to run automatically at a certain time?
Yes, using Windows Task Scheduler. Search for "Task Scheduler", create a new task, point it to your .bat file, and set the time or event that should trigger it. This is how people automate backups or maintenance tasks to run every night without manual work.
What happens if I double-click a .bat file by mistake?
It runs when ready. If it is a .bat file you created and you know what it does, that is fine. If it is a file from an unknown source, close the Command Prompt window as fast as you can. If you are worried about what it did, restart your computer to be safe.
Can I turn a .bat file into a .exe file so it looks more like a regular program?
Yes, using free tools like Bat to Exe Converter, but it is not necessary. A .bat file works fine as is. Converting it to .exe makes it harder for someone to read what it does, which can be useful if you are sharing it, but it also makes it slightly riskier to run from unknown sources because you cannot easily see the commands inside.