How To Create a BAT File

A batch (or BAT) file represents a script file that stores a series of commands to be executed in a serial order. Such files are often used to load programs, run several simultaneous processes, or automate repetitive tasks. Contrary to popular belief, creating BAT files doesn’t require advanced computer skills.

How To Create a BAT File

If you want to learn how to create a BAT file, look no further. This article provides detailed step-by-step instructions on how to create different BAT files.

How to Create a BAT File Windows 11

Creating BAT files in Windows doesn’t have to be complicated. Here’s how to make a basic BAT file:

  1. Open the Start menu, start typing “Notepad,” and open it.
  2. Type these lines in the text file:
    @ECHO OFF
    ECHO Hello and welcome to batch scripting! If you’re seeing this text, it means you’ve successfully created a BAT file in Windows. Great job!
    PAUSE
    “.
  3. Select “File.”
  4. Choose “Save as.”
  5. Name the file. We recommend “Test Bat” or something similar. Remember that you’ll need to add “.bat” at the end of the file’s name because it won’t work without it. Moreover, ensure “All Files” is selected next to “Save as type.” Save the file to the desired location.
  6. Find the file and open it to test it out. You should see a command window with this text: “Hello and welcome to batch scripting! If you see this text, you’ve successfully created a BAT file in Windows. Great job!”

How to Create a BAT File to Move Files

BAT files can move one or more files from one folder to another. To create one, you’ll need to find the proper folder paths that make the transfer possible. Follow the instructions below to find and copy the folders’ paths:

  1. Find the folder from which you want to move files and right-click on it.
  2. Select “Properties.”
  3. Copy the text on the right of “Location.” For example, “C:\Users\User”.
  4. Open the Notepad app and paste the text.
  5. Locate the destination folder and right-click on it.
  6. Choose “Properties.”
  7. Copy the text next to “Location.” For example, “C:\Users\User\Desktop.”
  8. Paste the text below the source folder’s location.

Now that you have the folders’ paths, it’s time to create the file:

  1. Type the following text in Notepad:
    @ECHO OFF
    move Source-Path*.* Destination-Path
    “.
    “Source-Path” is the location of the source folder, while “Destination-Path” is the location of the destination folder. Remember that if any part of a folder’s path has two or more words, you must place that part in quotes.
  2. Press “File.”
  3. Select “Save as.”
  4. Name the file and save it to the desired location. When naming the file, insert “.bat” at the end, for example, “move.bat.” Also, select “All Files” in the “Save as type” box.
  5. Open the BAT file, and the files from the source folder will be moved automatically to the destination folder.

How to Create a BAT File to Execute a Command

With BAT files, you can execute numerous commands. All you need to do is find the proper syntax for the order you want to run. Here are some of the popular ones:

  • DEL – This command deletes files.
  • REN – This command renames files and directories.
  • TIME – This command displays or sets the time.
  • CHKDSK – This command scans the disk for potential issues.
  • EXPAND – This command extracts files from compressed files.

Let’s try the command to delete a file. Here’s how to use it:

  1. Open Notepad.
  2. Type the following text:
    @ECHO OFF
    DEL [file destination and name]
    “.
  3. Select “File.”
  4. Choose “Save as.”
  5. Name the file and save it. When naming the file, type “.bat” at the end; otherwise, the command won’t work. For example, call the file “delete.bat”. Choose “All Files” in the “Save as type” box.
  6. Run the BAT file, and the file whose destination and name you entered will be automatically deleted.

How to Create a BAT File to Copy Files

With a BAT file, you can copy and paste files from one folder to another. Like moving files, you’ll need to know the file’s location to copy and paste it. Here’s what you need to do:

  1. Find the file you wish to copy and right-click on it.
  2. Choose “Properties” and copy the file’s location.
  3. Repeat the steps to save the location of the destination folder.
  4. Open Notepad.
  5. Type the following lines:
    ECHO OFF
    copy [source] [destination]
    “.
  6. Choose “File.”
  7. Select “Save as.”
  8. Name the file and save it to a folder of your choice. Correctly naming the file is crucial for creating a BAT file successfully. Use “.bat” at the end of the file’s name because it can’t work without it. For example, “copy.bat”. Select “All Files” in the “Save as type” box.
  9. Open the file, and the file whose location you entered will be copied to the desired destination.

How to Create a BAT File to Map a Network Drive

If you want to create a BAT file to map a network drive, follow the instructions below:

  1. Open the Start menu, start typing “Notepad,” and open it.
  2. Type the following lines:
    ECHO Create new [drive letter] drive mapping
    @net use [drive letter]:\Network path/persistent: yes
    :exit
    @pause
    “.
  3. Choose “File.”
  4. Press “Save as.”
  5. Name the BAT file and save it to the desired folder. Ensure to type “.bat” at the end, for example: “map.bat.” Then, choose “All Files” in the “Save as type” box.
  6. Run the file, and your network drive will be mapped automatically.

Save Time With BAT Files

BAT files are a particular file type that contains different commands that can be executed without user input. Once you create a file with a specific order, you only need to open it to run that command. Although making BAT files may seem overwhelming and confusing at first, it becomes much easier after you’ve had some practice. You can use them to launch programs, execute specific commands, create prompts, mount a virtual drive, copy folders/files, and perform tasks like updating, copying, moving, and more.

Do you often use BAT files? What is the one you use most often? Tell us in the comments section below.

Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.