File Extension File Extension Guide

What is a BAT File?Windows Script

A technical reference for the .bat extension, the Windows batch script. What a BAT file is, how to create, run, open and edit one, the common commands it uses and how it compares to CMD and PowerShell.

Batch Script 🪟 Windows ⚙️ Automation 📄 Plain Text
.BAT

Windows Batch Script

Type:Script file
Extension:.bat
Runs in:Command Prompt
Format:Plain text
System:Windows, DOS

📖 What is a BAT File?

A BAT file is a Windows script that holds a list of commands and runs them one after another. The name is short for batch file, and it uses the .bat extension. It is a plain-text file, so it is really just commands typed in order, saved so Windows can run them together.

When you run a BAT file, the Command Prompt reads it line by line from top to bottom and carries out each command in turn. This is what makes it a batch file, it runs a whole batch of commands in one go rather than you typing them one at a time.

Batch files go back to the days of DOS and are still part of Windows today. Because they need no special software and are plain text, they are a quick way to automate small jobs on a Windows PC.

A BAT file runs its commands in order, top to bottom backup.bat @echo off echo Start copy ... pause plain-text commands Command Prompt reads line by line console Start 1 file copied Press any key shows the output

Key Characteristics

  • A Windows script, run by the Command Prompt
  • Plain text, editable in any text editor
  • Runs commands in order, top to bottom
  • Needs no extra software, built into Windows

Good to Know

  • Automates tasks, from backups to cleanup
  • Written in Notepad, no coding tools needed
  • Close cousin of .cmd, a newer equivalent
  • Can be scheduled, with Task Scheduler
💡 Why it matters: A task that would take many manual commands can be saved once as a BAT file and repeated with a double-click. That is why batch files are an everyday tool for automating routine jobs on Windows.

⚡ Quick Facts

File Extension.bat
Full NameBatch file, or batch script
CategoryWindows script file
Runs InCommand Prompt, cmd.exe
FormatPlain text
SystemsWindows, DOS, OS/2
Create and Edit WithNotepad or any text editor
Common UsesAutomating and scheduling tasks
Run ByDouble-click, or from Command Prompt
Related Extensions.cmd, .ps1, .vbs, .sh

🎯 What a BAT File Is Used For

Batch files shine at jobs you do again and again. Instead of typing the same commands each time, you save them once and run them with a click.

Backups

Backups

Copy files or folders to a backup location in one step, the same way every time.

Cleanup

Cleanup

Delete temporary files or sort a messy folder by type without doing it by hand.

Launch

Launch Programs

Open several apps, websites or services together with a single double-click.

Admin

System Tasks

Run maintenance commands, map network drives or set up a machine for a new user.

📝 How to Open and Edit a BAT File

There is an important difference here. Double-clicking a BAT file runs it, so to see or change what is inside, you open it for editing instead.

To see or change it

Right-click the BAT file and choose Edit, which opens it in Notepad. There you can read the commands and change them, then save.

To run it

Double-click the file. This does not show the code, it carries out the commands, so only do this with a BAT file you trust.

💡 Any editor works: Because a BAT file is plain text, Notepad, WordPad or a code editor like VS Code all open it for editing. A code editor adds colour highlighting that makes longer scripts easier to read.

▶️ How to Run a BAT File

There are a few ways to run a batch file, depending on whether you want a quick launch or more control over what you see.

1

Double-click it

The simplest way. Find the BAT file and double-click it, and a Command Prompt window opens and runs the commands.

2

From Command Prompt

Open Command Prompt, move to the file's folder with the cd command, then type the file name to run it. This keeps the window open to see output.

3

Run as administrator

For tasks that change system settings, right-click the BAT file and choose Run as administrator, which gives it the extra permissions.

⚠️ The window closes too fast? If a BAT file flashes open and shuts before you can read it, add the line pause at the end. It holds the window open until you press a key.

🛠️ How to Create a BAT File

Making a batch file takes nothing more than Notepad. You type the commands, then save the file with the right extension.

1

Open Notepad

Open Notepad or any text editor. This is where you write the commands the batch file will run.

2

Type the commands

Write each command on its own line, in the order you want them to run, such as an echo message and a pause.

3

Save as .bat

Choose Save As, set the type to All Files, and end the name with .bat, such as backup.bat, rather than leaving it .txt.

REM a simple batch file

  @echo off # hide the command lines
  echo Hello and welcome! # print a message
  pause # wait so the window stays open
From Notepad to a working batch file 1. Write commands in Notepad 2. Save as .bat, not .txt 3. Run double-click to start it Edit later right-click, choose Edit double-click runs it, right-click Edit opens it to change

⌨️ Common Batch Commands

A handful of commands do most of the work in batch files. Knowing these makes almost any script readable.

@echo offHides the command lines so only the output shows, usually the first line of a script.
echoPrints text to the screen, for example a status message.
pauseStops and waits for a key press, which keeps the window open to read output.
remMarks a comment, a note in the script that Windows ignores when running.
setCreates a variable to store a value the script can reuse later.
cdChanges the current folder the script is working in.

🚀 Beyond the Basics

Once the simple commands make sense, batch files can do a lot more. A few common next steps come up again and again.

Logic and loops

Commands like IF, FOR and GOTO let a script make decisions and repeat steps, so it can react to conditions rather than run a fixed list.

Run it silently

To run without the black window showing, schedule it in Task Scheduler set to Hidden, or launch it through a short VBScript wrapper.

Convert to EXE

Tools such as Bat To Exe Converter, or the built-in IExpress, turn a BAT file into a standalone .exe for easier sharing.

⚔️ BAT vs CMD and PowerShell

BAT is not the only way to script on Windows. Two close relatives come up often, and each fits a different job.

FormatExtensionRuns InBest For
Batch.batCommand PromptSimple, quick tasks
CMD.cmdCommand PromptSame, better error handling
PowerShell.ps1PowerShellComplex automation

In short, a .cmd file is nearly the same as a .bat and runs the same way, with slightly better error handling on modern Windows. PowerShell is a more capable scripting language for bigger jobs. For simple automation, a BAT file is often all you need.

🛡️ Is a BAT File Safe?

⚠️ Only run BAT files you trust: A batch file is just text and is not harmful on its own, but it can run any command, including ones that delete files or download programs. A malicious BAT file can do real damage, so never run one from a source you do not trust.

Because a BAT file is plain text, the safe move is to read it before running it. Right-click and choose Edit to see exactly what commands it contains. If anything looks unfamiliar or aggressive, do not run it.

Be extra careful with Run as administrator, which gives a script full power over the system. Keep your antivirus active, since it can flag known bad scripts, and treat an unexpected BAT file the same way you would treat any unknown program.

🔀 Related Formats

BAT sits among the Windows scripting formats you compare it with.

.cmdA newer batch script, run the same way by the Command Prompt, with minor improvements.
.ps1A PowerShell script, a more capable language for complex Windows automation.
.vbsA VBScript file, an older Windows scripting option for more involved logic.
.shA shell script, the equivalent of a batch file on Linux and macOS.
.exeA compiled Windows program, unlike a BAT file which stays readable text.

❓ Frequently Asked Questions

To see what is inside, right-click the BAT file and choose Edit, which opens it in Notepad so you can read and change the commands. To run it instead, double-click the file and the Command Prompt carries out the commands. Because double-clicking runs a batch file rather than showing it, only do that with a BAT file you trust.

The simplest way is to double-click it, which opens a Command Prompt window and runs the commands. You can also open Command Prompt, move to the file's folder with the cd command and type the file name. For tasks that change system settings, right-click the file and choose Run as administrator to give it the needed permissions.

Open Notepad or any text editor, type your commands one per line, then choose Save As. Set the file type to All Files, and end the name with .bat instead of .txt, for example backup.bat. That saves it as a batch file you can run by double-clicking. No special programming software is needed, since a BAT file is plain text.

Right-click the BAT file and choose Edit, which opens it in Notepad ready to change. Make your edits and save. You can also open it in WordPad or a code editor like VS Code, which adds colour highlighting that makes longer scripts easier to read. Avoid double-clicking to edit, since that runs the file instead of opening it.

Because it finished running. A batch file opens a Command Prompt window, runs its commands and then closes as soon as it is done, often too fast to read. Add the line pause at the end of the file, which holds the window open until you press a key. That lets you see any messages or errors the script produced.

They are nearly the same. Both are batch scripts run by the Command Prompt, and both hold commands in plain text. The .cmd extension is the newer form and behaves slightly differently in a few cases, with better handling of errors on modern Windows. For everyday scripts, a .bat and a .cmd file work the same way.

A batch file is a simple script of Command Prompt commands, saved as .bat, and is ideal for quick, straightforward tasks. PowerShell, saved as .ps1, is a far more capable scripting language built for complex automation, with variables, functions and proper error handling. Batch suits small jobs, while PowerShell suits larger or more involved ones.

A BAT file is only text, so opening it to read in Notepad is completely safe. Running one is different, because it can carry out any command, including deleting files or downloading programs. A malicious batch file can do real harm, so never run one from a source you do not trust, and read it first by right-clicking and choosing Edit.

Not directly, because BAT files use Windows Command Prompt commands that macOS and Linux do not have. The equivalent on those systems is a shell script with a .sh extension. To do the same job on a Mac or Linux, you would rewrite the batch file's commands as a shell script rather than running the .bat itself.

A BAT file contains a list of commands in plain text, run in order by the Command Prompt. Typical lines include @echo off to hide the commands, echo to print messages, pause to wait for a key, and rem for comments. It can run almost any command available at the command line, which is what makes batch files flexible.

Use the Windows Task Scheduler. Create a new task, set when it should run, such as daily or at startup, and point it at your BAT file as the program to start. Task Scheduler then runs the batch file on that schedule without you doing anything, which is handy for regular backups or cleanup jobs.

BAT is short for batch. A batch file runs a batch of commands in sequence, which is where the name comes from. The extension is written as .bat, and the file is a plain-text Windows script that the Command Prompt reads and runs line by line. A closely related newer form uses the .cmd extension.

Use a converter tool such as Bat To Exe Converter, or the IExpress wizard built into Windows, which wraps your batch file into a standalone .exe program. This makes it easier to share, since the person running it does not see or need the raw script, and some tools can also hide the console window. The commands still do the same thing, they are just packaged as an executable.

A few ways work. Schedule the file in Task Scheduler with the run mode set to Hidden, launch it through a short VBScript that runs it in a hidden window, or convert it to an EXE built to run invisibly. Each hides the black console so the script works quietly in the background. Take care running scripts you cannot see, since problems are harder to spot.

Yes. Batch files support conditional and repeating logic through commands like IF, FOR and GOTO. IF runs a command only when a condition is met, FOR repeats a command over a set of items, and GOTO jumps to a labelled point in the script. These let a batch file react to results and loop over files rather than run a single fixed list of commands.

📝 Summary

A BAT file is a Windows batch script, a plain-text file with the .bat extension that holds a list of commands the Command Prompt runs in order. It is used to automate tasks like backups, cleanup and launching programs, and needs no special software since you write it in Notepad. Double-click to run it, or right-click and choose Edit to read and change the commands, and add pause so the window stays open. A .cmd file is a close equivalent, while PowerShell handles bigger jobs. Since a batch file can run any command, only run ones you trust.