Windows 10

Batch File To Create Folders From a List

In this tutorial, you will learn how to create multiple folders in Windows using a batch file and a FOR loop. This is particularly useful when you need to automate the creation of several directories from a predefined list.

Batch files are an effective way to execute repetitive tasks without manual intervention, making them ideal for system administrators, developers, and IT professionals.
 
 

✅ Batch File to Create Folders from a List

The following example uses a FOR loop to create six folders named A, B, C, D, E, and F from a list:

@echo off
set "folders= A"
set "folders=%folders% B"
set "folders=%folders% C"
set "folders=%folders% D"
set "folders=%folders% E"
set "folders=%folders% F"

for %%i in (%folders%) do md %%i

📂 Output:
When executed, this script will create the following folders in the current working directory:
 

 
🔍 Explanation:
@echo off ➤ Prevents the commands from being displayed in the command prompt for cleaner output.

set "folders=..." ➤ Initializes a variable with the names of folders to be created.

for %%i in (%folders%) do md %%i ➤ Iterates over each item in the folders variable and creates the folder using the md (make directory) command.
 
💡 Tips:

  • You can customize the list of folder names by editing the set “folders=” lines.
  • To create folders in a specific location, prefix the folder names with a path, e.g., md “C:\Projects\%%i”.

🧠 Use Cases:

  • Setting up project directories
  • Creating monthly or weekly report folders
  • Initializing structures for data backups or logs

 

🧾 Summary

Using a batch file to create multiple folders from a list is a smart way to automate directory setup. This method is scalable, efficient, and can easily be integrated into larger automation scripts.
 

Leave a Reply

Your email address will not be published. Required fields are marked *