WATCH FULL VIDEO BELOW
Tech

How To Create a BAT File

A batch (or BAT) file represents a script file that stores a series of commands set 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’re interested in learning 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 create a basic BAT file:

  1. Open the Start menu, start typing “Notepad,” and open it.
    How to Create a BAT File Windows 11 1
  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
    ”.
    How to Create a BAT File Windows 11 2
  3. Select “File.”
    How to Create a BAT File Windows 11 3
  4. Choose “Save as.”
    How to Create a BAT File Windows 11 4
  5. Name the file. We recommend “Test Bat” or something similar. Keep in mind 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.
    How to Create a BAT File Windows 11 5
  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’re seeing this text, it means you’ve successfully created a BAT file in Windows. Great job!”
    How to Create a BAT File Windows 11 6

How to Create a BAT File to Move Files

BAT files can be used to 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.
    How to Create a BAT File to Move Files 1
  2. Select “Properties.”
    How to Create a BAT File to Move Files 2
  3. Copy the text on the right of “Location.” For example, “C:\Users\User”.
    How to Create a BAT File to Move Files 3
  4. Open the Notepad app and paste the text.
    How to Create a BAT File to Move Files 4
  5. Locate the destination folder and right-click on it.
    How to Create a BAT File to Move Files 5
  6. Choose “Properties.”
    How to Create a BAT File to Move Files 6
  7. Copy the text next to “Location.” For example, “C:\Users\User\Desktop”.
    How to Create a BAT File to Move Files 7 1
  8. Paste the text below the source folder’s location.
    How to Create a BAT File to Move Files 8

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. Keep in mind that if any part of a folder’s path has two or more words, you’ll need to place that part in quotes.
    folders paths 1 1
  2. Press “File.”
    folders paths 2 1
  3. Select “Save as.”
    folders paths 3 1
  4. Name the file and save it to the desired location. When naming the file, ensure to insert “.bat” at the end, for example, “move.bat”. Also, select “All Files” next to “Save as type.”
    folders paths 4 1
  5. Open the BAT file, and the files from the source folder will be moved automatically to the destination folder.
    folders paths 5 1

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 right 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.
    How to Create a BAT File to Execute a Command 1
  2. Type the following text:
    @ECHO OFF
    DEL [file destination and name]
    ”.
    How to Create a BAT File to Execute a Command 2
  3. Select “File.”
    How to Create a BAT File to Execute a Command 3
  4. Choose “Save as.”
    How to Create a BAT File to Execute a Command 4
  5. Name the file and save it. When naming the file, type “.bat” at the end; otherwise, the command won’t work. For example, name the file “delete.bat”. Choose “All Files” next to “Save as type.”
    How to Create a BAT File to Execute a Command 5
  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 Execute a Command 6

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 if you want to copy and paste it. Here’s what you need to do:

  1. Find the file you want to copy and right-click on it.
    How to Create a BAT File to Copy Files 1
  2. Choose “Properties” and copy the file’s location.
    How to Create a BAT File to Copy Files 2
  3. Repeat the steps to save the location of the destination folder.
  4. Open Notepad.
    How to Create a BAT File to Execute a Command 1
  5. Type the following lines:
    ECHO OFF
    copy [source] [destination]
    ”.
    How to Create a BAT File to Copy Files 5
  6. Choose “File.”
    How to Create a BAT File to Copy Files 6
  7. Select “Save as.”
    How to Create a BAT File to Copy Files 7
  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” next to “Save as type.”
    How to Create a BAT File to Copy Files 8
  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 Copy Files 9

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.
    How to Create a BAT File to Execute a Command 1
  2. Type the following lines:
    ECHO Create new [drive letter] drive mapping
    @net use [drive letter]:\Network path/persistent: yes
    :exit
    @pause
    ”.
    How to Create a BAT File to Map a Network Drive 1
  3. Choose “File.”
    How to Create a BAT File to Map a Network Drive 3
  4. Press “Save as.”
    How to Create a BAT File to Map a Network Drive 4
  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” next to “Save as type.”
    How to Create a BAT File to Map a Network Drive 5
  6. Run the file, and your network drive will be mapped automatically.
    How to Create a BAT File to Map a Network Drive 6

Save Time With BAT Files

BAT files are special file types that contain 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.

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

Muhabarishaji

🧪 |Medical Laboratory Scientist 🥇 | Mindset over Everything. 
 🤝 | Let's Grow Together.

Related Articles

Back to top button