Thursday, November 6, 2025

Create Any Number of Folders using Windows Batch Scripting

Run the following code to create 5 folders:


My folder1

My folder2

My folder3

My folder4

My folder5



@echo off

set "foldername=My folder"

set "count=5"


REM Replacement parameter is prefixed with %% in script file

REM The set variables are expanded using % symbol sandwitching them



FOR /L %%i in (1,1,%count%) DO (

MKDIR "%foldername%%%i"


)

pause


Tips

  • You can test the script using ECHO in place of MKDIR. This will show the result in the window.
  • You can change the foldername and count as per the need.
  • To List only folders, use the following switch

D:\BAT Examples\>dir/b/A:D
My folder1
My folder2
My folder3
My folder4
My folder5 










No comments:

Post a Comment

Hot Topics