Solved Batch File Mkdir folders in ascending order?

April 18, 2011 at 09:06:11
Specs: Windows 7, XP
I am looking for an example of a .bat file that will accomplish three tasks. (it may need to be .vbs as its kind of complicated)

1) I need to create multiple folders inside a directory (i.e. Folder1, Folder2,...)

2)The first three letters of the folders MUST always be named "DET" and the ascending numbers MUST start at "100" and go up. (i.e. DET100, DET101, DET102...)

3) I would like to be able to specify how many folders to create each time I run the script without having to manually edit the script each time.
-Maybe a prompt stating "How many DET folders would you like to create?"

This script will hopefully help negate the numerous error messages from our various programs when trying to navigate to file directories that aren't structured correctly.

Hopefully someone out there is master at this kind of stuff and can help me out??



See More: Batch File Mkdir folders in ascending order?

Report •

#1
April 18, 2011 at 12:18:32

@echo off & setlocal
set /P DETno=How many DET folders would you like to create?^>
for /L %%j in (100 1 %DETno%) do md DET%%j

You need to run the above script IN the folder where subfolders have to be generated. You can issue a CD command to do this or if the folder remains always the same add the command

cd Your _PathName

after the first line (@echo off & setlocal).

By the way this is NT batch that has nothing to do with DOS or Disk Operating System Forum since Win 7 and XP have no DOS at all.


Report •

#2
April 19, 2011 at 05:01:36
Thanks for your help!
The prompt is working, but when I enter the number of folders to create and hit enter the CMD window closes and the folders aren't created.
Here is the code I am using;

@echo off & setlocal
cd C:\Test
set /P DETno=How many DET folders would you like to create?^>
for /L %%j in (100 1 %DETno%) do md DET%%j

Is there a way to have it automatically create the folders in whatever directory the batch file is located without having to enter a path?
*I have tried running the scrip without the line "cd C:\Test" and it does the same thing. (no folders are created)


Report •

#3
April 19, 2011 at 05:49:01
✔ Best Answer
Sorry, my mistake, the below script works fine. To avoid to type the Pathname just store the batch file in the folder where the subdirectories have to be created and double click it to run.

@echo off & setlocal
set /P DETno=How many DET folders would you like to create?^>
set /A DETno+=99
for /L %%j in (100 1 %DETno%) do if not exist DET%%j md DET%%j


Report •

Related Solutions

#4
June 14, 2011 at 00:27:28
Hey dear wich batch file of making multiple folder u have made is reallly so nice.............................
bt in wich we have to edit number. so hw to make that type of batch file in wich we make double click n outo matically it makes multiple folders of desire numbers... plzzz reply....

Report •

Ask Question