How to edit a batch file

Updated: 12/31/2020 by Computer Hope
Edit batch file

To edit a batch file, follow the steps below for where you want to edit the file.

Edit a batch file from within Windows

Batch files are plain-text files, which means they can be edited as a text file by right-clicking the file and clicking Edit as shown in the picture.

Once you've clicked edit, your default text editor opens the file and allows it to be modified.

You can also open any text editor or word processor and from within that program open the batch file.

After making all changes save and exit the file. If you are asked how to save the file, make sure it is saved with a .bat file extension.

Tip

For information about the available command, see: What commands are available in a batch file?

Edit a bat file in a Command Prompt (DOS)

To edit a batch file in MS-DOS, follow the steps below.

Note

New versions of Windows or computers running a 64-bit version of Windows no longer support the edit command, which means these steps no longer work. Use the above steps if you are running the latest version of Windows. For help with determining your version of Windows, see: How to determine if you have a 32-bit or 64-bit CPU.

  1. Open an MS-DOS prompt.
  2. In the MS-DOS prompt, type: edit test.bat and press Enter.
  3. If typed correctly, you'll see a blue edit screen. In the screen, type:
@echo off
echo Hello this a test batch file
pause
dir c:\windows
pause
  1. After entering these lines, click File and choose exit; when prompted to save, click Yes. Users who do not have a mouse can accomplish this same task by pressing Alt+F to access the file menu, then X to exit. Press Enter to save changes.
  2. Once you are back at the MS-DOS prompt, type: test and press Enter to execute the test.bat file.
Tip

To add more lines to this batch file, type edit test.bat to open the file for editing.

Additional information about the MS-DOS edit command is in our edit command page. Some versions of MS-DOS and bootable diskettes may not have the edit command. If this the case, you would either need to obtain the edit.com file or use the copy con command.

Tip

For information about the available command, see: What commands are available in a batch file?