Home / Microsoft / Microsoft DOS / Using a for loop to make unlimited folders
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 3 4  All - (Bottom) Print
Author Topic: Using a for loop to make unlimited folders  (Read 6612 times)
BatchFileCommand
Topic Starter
Hopeful



Thanked: 1
Posts: 339




« on: February 14, 2009, 07:18:31 PM »

This is my program which makes folders. The user just types in how many folders he wants to make and he can make that many.


Code: [Select]
@echo off
title Folder Maker
color 0a

cls
set /p folder=How many folders would you like to make:
for /l %%a in (1,1,%folder%) do (
cls
set /p foldername=What would you like to name folder #%%a:
mkdir "%foldername%"
set foldername=
)

msg * All folders created!

But this throws back an error message saying "The system could not find the enviroment option that was entered"  . Any way to fix this ?
IP logged

οτη άβγαλτος μεταφ βαθμολογία
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,881

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #1 on: February 14, 2009, 07:22:11 PM »

QuickBasic, Freebasic, whatev.
Code: [Select]
Dim NumFolders as Long
Dim CurrFolder as String,I as long
Const FolderName="FOLDER"
numfolders=val(COMMAND$)
chDrive "C:"
chDir "\"
For I = 1 to numfolders
    mkDir CurrDIR$ + "FOLDER"
    chDir CURRDIR$ + "FOLDER"

next I



Sorry, couldn't resist  ;D



where does it throw the error? Could you place trace echos in the batch?
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
BatchFileCommand
Topic Starter
Hopeful



Thanked: 1
Posts: 339




« Reply #2 on: February 14, 2009, 07:44:08 PM »

After I name the folder to make it throws the error message.
IP logged

οτη άβγαλτος μεταφ βαθμολογία
computeruler
Egghead



Thanked: 63
Posts: 3,396

Experience: Experienced
OS: Mac OS

1 1
« Reply #3 on: February 14, 2009, 07:45:51 PM »

And why would you need something like this?  More computer pranks?
IP logged
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,881

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #4 on: February 14, 2009, 08:00:33 PM »

maybe he wants to see how deep it will go?
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
BatchFileCommand
Topic Starter
Hopeful



Thanked: 1
Posts: 339




« Reply #5 on: February 14, 2009, 08:25:38 PM »

And why would you need something like this?  More computer pranks?

This is quite far from computer pranks. Think before you speak. This is so you don't have to spend
you time making a menu to ask how many folders you want to make.
IP logged

οτη άβγαλτος μεταφ βαθμολογία
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,881

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #6 on: February 14, 2009, 08:26:36 PM »

And why would you need something like this?  More computer pranks?

This is quite far from computer pranks. Think before you speak. This is so you don't have to spend
you time making a menu to ask how many folders you want to make.


of which the practical applications are?
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
BatchFileCommand
Topic Starter
Hopeful



Thanked: 1
Posts: 339




« Reply #7 on: February 14, 2009, 08:35:41 PM »

Quote
of which the practical applications are?

I don't quite get what you mean there. But, back to the question. Is there a way to fix it so it won't throw out that error message and make the folders.
IP logged

οτη άβγαλτος μεταφ βαθμολογία
GuruGary
Adviser



Posts: 771




« Reply #8 on: February 14, 2009, 09:05:33 PM »

When you use environment variables that were set inside a FOR loop, you typically need to use the "setlocal enabledelayedexpansion" and then access them with ! instead of %.  Here is your script with those 2 changes:

Code: [Select]
@echo off
setlocal enabledelayedexpansion
title Folder Maker
color 0a

cls
set /p folder=How many folders would you like to make:
for /l %%a in (1,1,%folder%) do (
cls
set /p foldername=What would you like to name folder #%%a:
mkdir "!foldername!"
set foldername=
)

msg * All folders created!
IP logged
BatchFileCommand
Topic Starter
Hopeful



Thanked: 1
Posts: 339




« Reply #9 on: February 15, 2009, 08:23:11 AM »

Thanks, that worked.
IP logged

οτη άβγαλτος μεταφ βαθμολογία
computeruler
Egghead



Thanked: 63
Posts: 3,396

Experience: Experienced
OS: Mac OS

1 1
« Reply #10 on: February 15, 2009, 10:43:30 AM »

BC ment why would you need to make all those folders
IP logged
BatchFileCommand
Topic Starter
Hopeful



Thanked: 1
Posts: 339




« Reply #11 on: February 15, 2009, 12:23:24 PM »

It's not about how many folders I can make. It's that I don't want to make a big menu asking how many folders I want to make.
IP logged

οτη άβγαλτος μεταφ βαθμολογία
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,881

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #12 on: February 15, 2009, 12:27:14 PM »

It's not about how many folders I can make. It's that I don't want to make a big menu asking how many folders I want to make.


why would you want a menu that asks you to create folders when it's far easier to do so using md and cd commands?
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
computeruler
Egghead



Thanked: 63
Posts: 3,396

Experience: Experienced
OS: Mac OS

1 1
« Reply #13 on: February 15, 2009, 01:20:15 PM »

And I still want to know why you need to make so many folders
IP logged
Dias de verano
Guest
« Reply #14 on: February 15, 2009, 01:20:41 PM »

why would you want a menu that asks you to create folders when it's far easier to do so using md and cd commands?

Because beginning batch programmers love to create 150 line batch files with 56 labels that do the same thing as typing "DIR", maybe?
IP logged
Pages: [1] 2 3 4  All - (Top) Print 
Home / Microsoft / Microsoft DOS / Using a for loop to make unlimited folders « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.094 seconds with 20 queries.