What Is a BAT File?

How to open, edit, and convert BAT files

What to Know

  • A BAT file is a Windows Batch file.
  • Double-click to run it, or open it with Notepad for editing.
  • Convert to EXE with IExpress.

This article explains what a BAT file is, how to open one for execution, how to edit one to make changes to it, and how to convert a BAT file to EXE, MSI, or another format.

What Is a BAT File?

A file with the .BAT file extension is a Windows Batch file. It's a plain text file that contains various commands used for repetitive tasks or to run groups of scripts one after another.

Software of all types use BAT files for various purposes—for example, to copy or delete files, run applications, and shut down processes.

several BAT files in Windows 11

They're also called batch files, scripts, batch programs, command files, and shell scripts, and may instead use the .CMD extension.

Working with BAT files can be very dangerous to not only your personal files but also important system files. Take extreme caution before opening one.

How to Open a .BAT File

Even though the BAT extension immediately makes Windows recognize such a file as executable, they are still composed entirely of text commands. This means any text editor, such as Notepad, including in all versions of Windows, can open one for editing.

To open the BAT file in Notepad, right-click it and choose Show more options > Edit from the menu (or just Edit in some Windows versions). You might find it helpful to use more advanced text editors that support syntax highlighting when editing a BAT file.

Opening it in a text editor will display the code that makes up the file. For example, this is the text inside one used to empty the clipboard:

cmd /c "echo off | clip"

Here's another example of a BAT file that uses the ping command to see if the computer can reach a router with this particular IP address:


Again, as an executable file extension, take great care when opening BAT files you have received via email, downloaded from websites you're not familiar with, or even created yourself.

How to Use a BAT File

Using a BAT file in Windows is as simple as double-clicking or double-tapping it. You don't need to download any special program or tool.

To use the first example from above, entering that text into a text file with a text editor and then saving the file with the .BAT extension will make it an executable that you can open to immediately erase anything saved to the clipboard.

The second example will ping that IP address; the pause command keeps the Command Prompt window open when the process is finished so you can see the results.

If your file doesn't seem to be a text file, then you're probably not dealing with a BAT file. Check the file extension to make sure you aren't mixing it up with a BAK or BAR (Age of Empires 3 data) file.

How to Convert a .BAT File

As shown, the code of a BAT file is not hidden in any way, which means it's very easy to edit. Because certain instructions in one (such as the del command) can wreak havoc on your data, converting the BAT file to a format like EXE to make it more like an application file might be wise.

You can convert BAT to EXE using a few command line tools. See How-To Geek for directions on how to do that.

  • Windows' built-in IExpress tool provides another way to build an EXE file from a BAT file. Open it from the Run box with iexpress.exe.
  • Although the free version is only a trial, EXE to MSI Converter Pro can convert the resulting EXE file to an MSI (Windows Installer Package) file.
  • You can use the free NSSM command-line tool if you want to run a BAT file as a Windows Service.
  • PowerShell Scriptomatic can help you convert the code in a BAT file to a PowerShell script.

Instead of searching for a BAT to SH (bash shell script) converter to use the commands in programs such as Bourne Shell and Korn Shell, try just rewriting the script using the Bash language. The structure of the two formats is rather different because the files are used in different operating systems. There is a Stack Overflow thread and this Unix Shell Scripting tutorial for some information that might help you translate the commands manually.

Usually, you can't change a file extension (like BAT) to one that your computer recognizes and expect the newly renamed file to be usable. An actual file format conversion using one of the methods described above must take place in most cases. Given that BAT files are just text files with the .BAT extension, however, you can rename it to .TXT to open it with a text editor. Remember that doing a BAT-to-TXT conversion will prevent the batch file from executing its commands.

How to Save a .BAT File as a .TXT File

Instead of manually changing the file extension from BAT to TXT, you also can open the batch file in Notepad for editing and then save it to a new file, choosing .TXT as the file extension before saving instead of .BAT.

Saving to TXT in Notepad

This is also what you need to do when making a new BAT file in Notepad, but in reverse: save the default text document as BAT instead of TXT. In some programs, you might have to save it in the All Files file type, and then put the .bat extension on it yourself.

  • Is a BAT file dangerous?

    Although rare, BAT files can contain viruses, just like most other file formats. Scan any file you download online with an antivirus tool to avoid malware.

  • What language is a BAT file written in?

    Batch script is its own language. The main function of batch script is to automate repetitive commands.

  • What is a comment in a BAT file?

    Comments are lines of text that do not affect the execution of code. Comments typically include documentation such as the purpose of the BAT file. Use the REM (Remarks) command to add comments to BAT files.

  • What command is used to shutdown your computer in a BAT file?

    Shutdown - s. To shut down with a 10-second timer, use shutdown -s -t 10. The shutdown command should be preceded by @echo off.

Was this page helpful?