Make folders with different names

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kpropell
Posts: 14
Joined: 24 Aug 2009 10:11

Make folders with different names

#1 Post by kpropell » 08 Feb 2013 10:51

Hi!

Is there a way to make a batch-script which makes you input the number of folders you want to make, then ask you for it's names and then generates them?

Ex:

How many folders?
3

Name of folder 1:
My Documents
Name of folder 2:
My Music
Name of folder 3:
My Pictures

Edit:
Or simply makes you make unlimited number of folders untill you input 'Done'?

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Make folders with different names

#2 Post by Squashman » 08 Feb 2013 12:06

This is the basics of doing it. But really have to add in some error checking for valid input.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set /p num=Enter Number of Folders:
for /L %%G in (1,1,%num%) do (
     set /p folder=enter folder name:
     mkdir "!folder!"
)

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: Make folders with different names

#3 Post by Ocalabob » 08 Feb 2013 13:48

Greetings Squashman!
That is a handy little script for quickly creating temp folders while testing code.

Hat tip!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Make folders with different names

#4 Post by foxidrive » 08 Feb 2013 20:16

You could use this and just press enter alone to end the loop:

Code: Select all

@echo off
:loop
     set "folder="
     set /p "folder=enter folder name: "
     if defined folder (
        mkdir "%folder%"
        goto :loop
       rem do not remove the rem
     )

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: Make folders with different names

#5 Post by Ocalabob » 08 Feb 2013 20:48

Greetings foxidrive,
I just put my hat back on! :)
Clever use of REM and yes I did try to replace it. Fail.

Thank you for the script. That's two 'keepers' in one day for me.

Later.

kpropell
Posts: 14
Joined: 24 Aug 2009 10:11

Re: Make folders with different names

#6 Post by kpropell » 09 Feb 2013 02:32

It works wonders! I liked the two different ways of doing it, so thank you both :)

Post Reply