
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.
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:
- Open the Start menu, start typing “Notepad,” and open it.
- 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 - Select “File.”
- Choose “Save as.”
- 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.
- 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 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:
- Find the folder from which you want to move files and right-click on it.
- Select “Properties.”
- Copy the text on the right of “Location.” For example, “C:\Users\User”.
- Open the Notepad app and paste the text.
- Locate the destination folder and right-click on it.
- Choose “Properties.”
- Copy the text next to “Location.” For example, “C:\Users\User\Desktop”.
- Paste the text below the source folder’s location.
Now that you have the folders’ paths, it’s time to create the file:
- 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. - Press “File.”
- Select “Save as.”
- 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.”
- 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 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:
- Open Notepad.
- Type the following text:
“@ECHO OFF
”.
DEL [file destination and name] - Select “File.”
- Choose “Save as.”
- 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.”
- 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 if you want to copy and paste it. Here’s what you need to do:
- Find the file you want to copy and right-click on it.
- Choose “Properties” and copy the file’s location.
- Repeat the steps to save the location of the destination folder.
- Open Notepad.
- Type the following lines:
“ECHO OFF
”.
copy [source] [destination] - Choose “File.”
- Select “Save as.”
- 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.”
- 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:
- Open the Start menu, start typing “Notepad,” and open it.
- Type the following lines:
“ECHO Create new [drive letter] drive mapping
”.
@net use [drive letter]:\Network path/persistent: yes
:exit
@pause - Choose “File.”
- Press “Save as.”
- 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.”
- Run the file, and your network drive will be mapped automatically.
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.