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. They’re also called batch files, scripts, batch programs, command files, and shell scripts, and may instead use the .CMD extension.
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: 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:
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.
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.
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. 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.