Page 1 of 1

Make folders with different names

Posted: 08 Feb 2013 10:51
by kpropell
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'?

Re: Make folders with different names

Posted: 08 Feb 2013 12:06
by Squashman
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!"
)

Re: Make folders with different names

Posted: 08 Feb 2013 13:48
by Ocalabob
Greetings Squashman!
That is a handy little script for quickly creating temp folders while testing code.

Hat tip!

Re: Make folders with different names

Posted: 08 Feb 2013 20:16
by foxidrive
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
     )

Re: Make folders with different names

Posted: 08 Feb 2013 20:48
by Ocalabob
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.

Re: Make folders with different names

Posted: 09 Feb 2013 02:32
by kpropell
It works wonders! I liked the two different ways of doing it, so thank you both :)