How to Create Monthly Folders Using a Batch Script
Do you often find yourself manually creating folders for each month of the year? Why not automate this process with a simple batch script? In this tutorial, I'll show you how to create a batch script that generates 12 monthly folders with customized names. You can use this for organizing reports, projects, or any recurring tasks.
Key Features of the Script
- Customizable Prefix: You can specify the prefix (e.g., "Bulk Report").
- Customizable Suffix: You can specify the suffix (e.g., "2025").
- Month Format Options: Choose between short (Jan, Feb) or full (January, February) month names.
The Batch Code
@echo off
setlocal enabledelayedexpansion
:: Ask for prefix, suffix, and month format
set /p prefix="Enter the prefix (e.g., Bulk Report): "
set /p suffix="Enter the suffix (e.g., 2025): "
set /p month_format="Enter month format (short or full): "
:: Define month names
set "months_short=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
set "months_full=January February March April May June July August September October November December"
:: Validate month format
if /i "%month_format%" equ "short" (
set "months=!months_short!"
) else if /i "%month_format%" equ "full" (
set "months=!months_full!"
) else (
echo Invalid month format. Please use "short" or "full".
exit /b
)
:: Create folders
set count=1
for %%m in (!months!) do (
set folder_name="%prefix% !count! %%m-%suffix%"
echo Creating folder: !folder_name!
mkdir !folder_name!
set /a count+=1
)
echo All folders have been created.
pause
Step-by-Step Instructions
1. Open Notepad
- Press Windows + R, type
notepad, and hit Enter. - Copy and paste the above code into Notepad.
2. Save the Script
- Click File > Save As.
- Set the file type to All Files.
- Save the file with a
.batextension, likeCreateMonthlyFolders.bat.
3. Run the Script
- Double-click the
.batfile. - Enter the required inputs when prompted (prefix, suffix, and month format).
- The script will automatically create folders in the same directory as the
.batfile.
Interactive Button for Copying Code
Conclusion
This batch script is a handy tool to automate folder creation and save time. It’s perfect for organizing projects, reports, or other tasks that require a monthly folder structure. Try it out and let me know how it works for you!
No comments:
Post a Comment