Moving and arranging files on your computer can be time-consuming. In Windows, it is faster to create a batch file (.bat) and move multiple source files and subfolders to any destination folder. You can define the properties of such a .bat file in advance and transfer files later at your leisure.
A .bat file is a well-known yet little used secret of Windows that can execute different kinds of commands with actionable results.
This is the latest guide for creating a batch file in Windows 11 and 10 from scratch. We also show how to utilize such a .bat file to move files from any source to a destination folder.
Also read: 4 Easy Ways to Copy a Large Number of Files Quickly in Windows
What Do Batch Files Do in Windows?
A batch file in Windows is an automated script file that helps perform routine tasks using predefined commands without any further user action. With a batch file, you can set it to run automatically at a predefined hour in the background.
Also read: How to Convert Audio Files to Text
Create a Batch File from Scratch
You can create a .bat file in any Windows folder of your choice. To create it from scratch, simply go to the destination folder of your choice.
- Right-click to create a new .txt file that can be opened in Notepad. In Windows 11, you can also create a new .txt file via the context menu at the top of the file explorer window.
- Once the Notepad file is created, rename the extension from .txt to .bat.
- Ignore the “file will become unusable” message due to change in file name extension and click Yes. An empty batch file (.bat) has now been created with no contents. You can modify the contents of this file as shown in the following sections.
The .bat file is prominently visible in the folder. It can be deleted, copy-pasted, renamed, and transferred to any other folder.
Also read: How to Use Nearby Sharing to Share Files on Windows
Use Batch File to Create Folders and Subfolders
You can use a .bat file to create separate folders and subfolders whose contents and properties remain connected to the .bat file. No matter which PC location you move the .bat file to, the folders and subfolders will follow. Any contents saved in these folders can simply be moved by relocating the Master .bat file.
There are two ways to operate a .bat file with Notepad. In the first method shown below, open Notepad in Administrator mode from the Start menu.
Open the .bat file in Notepad from its saved folder location, and its contents will be populated.
Another direct way to work with a .bat file is to right-click the created .bat file, which allows you to “Edit using Notepad.” In Windows 10, it can be accessed directly with a right-click. In Windows 11, you have to click “Show more options” to see the Notepad option among other programs.
Once the Notepad file is opened, enter the following to create folders using folder names, then save the file and exit Notepad.
@echo off md FolderName1 FolderName2..."Folder Name3"
The purpose of @echo off
is to disable the display prompt. This way you won’t have to deal with the Command prompt, although it’s internally connected to .bat file processes. If your folder name should contain a space, put it inside quotes.
As soon as you double-click the .bat file, it will execute the command to create the new folders.
To create subfolders in any folder, modify the above code as shown here by mentioning the subfolder names after the folder name. Save the file and exit Notepad, then double-click the .bat file again.
md FolderName/SubFolder1 FolderName/SubFolder 2...
As shown here, the subfolders have been created.
Also read: How to Fix the “Someone Else Is Still Using This PC” Error in Windows
Move Files From One Folder to Another Using Batch Files
You can use .bat files to move files from any folder on your Windows PC to a destination folder of your choice. All you need is a proper folder path to complete the transfers in a bulk folder move.
The best way to know a folder’s path is to right-click and select “Properties” followed by “Location.” Copy-paste the location entirely into the bat. file.
To batch move files in a folder, we are using the “move” command.
As shown here, we are moving all the contents of “Folder A” to “Folder B.” The command is as follows:
move Source-Folder-Path*.* Destination-Folder-Path
Here, *.*
is a wildcard that tells Windows to copy all the files in the source folder. If any part of the folder path has a folder name with spaces, you need to enclose it within quotes.
Save the file and exit Notepad. The entire contents of one folder have been moved to another by double-clicking the .bat file.
If you want to move only select files, the code can be slightly modified by putting the file name ahead of *.* as shown below.
move Source-Folder-PathFile Name1, File Name2*.* Destination-Folder-Path
If you wish to move only specific file types between the folders, for example, .png files, modify the code by putting the filetype ahead of *.* as shown below.
move Source-Folder-Path*.file_type*.* Destination-Folder-Path
For example, to move all image files with .png extension, use the code below:
move Source-Folder-Path*.png*.* Destination-Folder-Path
As per the code, only .png files have been moved in this example.
You can replace the .png in the above example with .jpg, .pdf, .doc, .ppt, or any other file type you want to move.
Also read: Find and Open Files Using Command Prompt in Windows
Frequently Asked Questions
1. Can I use a batch file to rename multiple files?
Yes, you can, but a batch file isn’t necessary, as there are simpler ways to batch rename files in Windows.
2. Can batch files be dangerous?
Not all batch (.bat) files are dangerous. The ones you create don’t harm your system, as they run a legitimate script.
However, malware authors often use known Windows processes to infect healthy systems. Batch files execute a series of commands that cannot be stopped once the files have been double-clicked. This makes them a popular means to infect Windows systems. Most malicious .bat files, however, will not be allowed to download on your PC provided you haven’t disabled the SmartScreen filter.
When a malicious batch file does creep into your Downloads folder, Windows Defender will automatically alert you. If the .bat script is programmed to run on a double-click, it will be quarantined by Windows Defender.
3. Can I run a batch file as a startup program?
Yes. You can easily program a batch file to run each time Windows boots up. First, create a shortcut for the .bat file using a right-click. This shortcut can be saved on the desktop or anywhere else that’s convenient.
Paste the shortcut into the Windows Startup folder found at “C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.” You can also use the same Startup folder to remove the batch file from the startup programs list.
Our latest tutorials delivered straight to your inbox