Computer Hope

Microsoft => Microsoft DOS => Topic started by: BatchFileCommand on February 14, 2009, 07:18:31 PM

Title: Using a for loop to make unlimited folders
Post by: BatchFileCommand 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 ?
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer 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?
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 14, 2009, 07:44:08 PM
After I name the folder to make it throws the error message.
Title: Re: Using a for loop to make unlimited folders
Post by: computeruler on February 14, 2009, 07:45:51 PM
And why would you need something like this?  More computer pranks?
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 14, 2009, 08:00:33 PM
maybe he wants to see how deep it will go?
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand 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.
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer 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?
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand 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.
Title: Re: Using a for loop to make unlimited folders
Post by: GuruGary 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!
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 15, 2009, 08:23:11 AM
Thanks, that worked.
Title: Re: Using a for loop to make unlimited folders
Post by: computeruler on February 15, 2009, 10:43:30 AM
BC ment why would you need to make all those folders
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand 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.
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer 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?
Title: Re: Using a for loop to make unlimited folders
Post by: computeruler on February 15, 2009, 01:20:15 PM
And I still want to know why you need to make so many folders
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano 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?
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 15, 2009, 01:26:23 PM
No, with this I don't use labels. I do this.

Code: [Select]
if  %question%==1 (
mkdir %foldername%
)
if %question%==2 (
mkdir %foldername%
mkdir %foldername%
)


and so on. I don't use goto in this situation.

And I still want to know why you need to make so many folders

It's not like I'm actually going to make hundreds of folders.  I never even said I was going to make hundreds of folders. So will you just cool it.
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 15, 2009, 01:43:24 PM
I see sarcasm is wasted on you, BatchFileCommand. By the way, leave the attitude at the door in future, OK?
Title: Re: Using a for loop to make unlimited folders
Post by: computeruler on February 15, 2009, 01:53:07 PM
You mean the home page?
Title: Re: Using a for loop to make unlimited folders
Post by: BatchRocks on February 15, 2009, 05:05:15 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.

*WINK* Of course this isn't a 'prank'. I know the use for it, but, why is making a folder a "prank".

And I still want to know why you need to make so many folders
Stop being nosy, something can be hidden but useful, and not wanted to be public...
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 15, 2009, 06:22:54 PM
Oh. I also used the same strategy to move folders.
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 15, 2009, 07:48:11 PM
Oh. I also used the same strategy to move folders.
heh, strategy. Like it's some complicared algorithm involving balanced binary trees, when in fact it's just reinventing the wheel.

Although I suppose the creation of useless programs early on is one way of getting better. I still remember my first batch program. MENU.BAT, some ridiculous startup program for DOS that displayed a menu to the user. Absolutely zero vaue to anybody, which is where I think it strikes a parallel here.
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 15, 2009, 07:51:10 PM
Strategy doesn't have to be complicated at all.
Title: Re: Using a for loop to make unlimited folders
Post by: computeruler on February 16, 2009, 11:11:41 AM
If you want to hide something.... RAR file with a password
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 16, 2009, 11:34:04 AM
Strategy doesn't have to be complicated at all.

neither does making folders...
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 16, 2009, 01:10:45 PM
Exactly.

If you want to hide something.... RAR file with a password


What is the point of telling me that. If I want to hide something.

Code: [Select]
attrib "folder" +h +r
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 16, 2009, 01:12:39 PM



What is the point of telling me that. If I want to hide something.

Code: [Select]
attrib "folder" +h +r


That is literally the most naive thing I have ever seen on this forum.
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 16, 2009, 01:14:59 PM
No, it's not. Why would I put compress something to RAR, if you use the folder or file frequently a password would be roadkill.
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 16, 2009, 01:18:48 PM



What is the point of telling me that. If I want to hide something.

Code: [Select]
attrib "folder" +h +r


That is literally the most naive thing I have ever seen on this forum.

(http://i124.photobucket.com/albums/p29/badoit/showhid.jpg)
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 16, 2009, 01:21:31 PM
So, you just click, do not show hidden folders. This is on your own computer isn't it?
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 16, 2009, 01:25:10 PM
If you hide something with attrib, who are you hiding it from? Not yourself. That would be silly. Somebody else therefore. Who can click "show hidden files and folders" and see all your goat porn.
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 16, 2009, 01:32:24 PM
No, it's not. Why would I put compress something to RAR, if you use the folder or file frequently a password would be roadkill.


it doesn't hide it. anybody can access it. a quick dir /a will reveal the files, and changing a few options in windows explorer will allow them to be displayed there, too.

you also missed my previous point. If somebody can easily create folders in windows explorer or the command prompt, why add the additional complication of a clunky batch program to do this creation? RD is a wrapper to the OS function to remove directories which in and of itself is a paradigm exposed by the filesystem and subsequently stored on disk as a series of bytes. There are only so many levels of indirection before further abstraction becomes ridiculously unnecessary.


As the big C has told you, acting like you know everything doesn't make it true, and this is directly related to your attitude towards perfectly valid suggestions. Calling them "stupid" and so forth doesn't instantly make your silly quests to wrap simple DOS functions in pages and pages of prompts and added features that really just add unnecessary bloat to the basic, simple, and yet oh so powerful commands. It's also somewhat silly to hint at the suggestion of knowing what I think. It is, and still is one the more naive things I've seen on this forum. Security by obscurity is just foolishness- If you want to prevent something from getting into the hands of others, it needs to be heavily protected via passwords and the like, hiding the files will simply draw attention to them by making it obvious that an attempt was made to keep the files out of the view of the casual user.


Besides, what would you need to hide anyway? (which also begs the question of where this fork of the discussion came from)


EDIT:

password protected RAR files are the best way to store goat porn.
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 16, 2009, 01:38:07 PM
Look what I found on BFC's hard drive!

[Image Removed]
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 16, 2009, 01:39:53 PM
ooh! I need a copy of that fo.... for um... *Ahem* documentation purposes. in the case file. yeah. we must build up a case and I volunteer to harbor this disgusting material on my hard drive. I will access it frequently, but solely for the purpose of ensuring it didn't magically disappear.
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 16, 2009, 01:43:22 PM
That was a mild picture compared to some of the others.
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 16, 2009, 01:51:44 PM
Of course, of course, you could only have shown something that wasn't inappropriate. BFC how could you. Now I must make duplicates of these files and archive them safely on my drive and make sure they exist every day.

In exchange I will provide the newest edition of "Goat Love: Getting the hairs out"

Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 16, 2009, 01:56:05 PM
[image removed]

Incidentally, if you want to store things away from prying eyes, not only password the rar file, but also give it a non-informative name, such as a mixture of letters and numbers, and take off the extension. That way, a casual click in Explorer will get the wannabe viewer nowhere. The command line rar.exe will extract from such a file if you use a wildcard for the filespec. (rar e *.* will find the header and merrily extract from any archive it finds)


Title: Re: Using a for loop to make unlimited folders
Post by: BatchRocks on February 16, 2009, 05:34:32 PM
Dias, stop being a jerk and bossing everyone around.

Hiding the file, it's literally, HIDDEN, there aren't any buttons to 'unhide' or anything.
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 16, 2009, 06:13:56 PM
Go get yourself banned with those pictures. That's flaming.
Title: Re: Using a for loop to make unlimited folders
Post by: Carbon Dudeoxide on February 16, 2009, 06:24:32 PM
Useless images removed by request.

BTW Hidden files can be seen as shown in Dias' post.
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 17, 2009, 03:20:09 AM
Dias, stop being a jerk and bossing everyone around.

Hiding the file, it's literally, HIDDEN, there aren't any buttons to 'unhide' or anything.

YES. THERE IS. It's a option right in windows explorer, "Show hidden files" (DER! I WONDER WHAT THAT DOES?) and a simple switch on a dir will reveal the files. there is nothing "hidden" about them.

The only thing they will prevent is some casual user stumbling upon them- but 75% of the computer literate population is aware of the hidden files and folders checkbox.


Dias isn't being a jerk. BFC is being the pompous know it all without the knowledge to back it up. Dias is a know it all, but only where applicable.

Rather then simply SAY there is no way to "unhide" the file, maybe you should actually venture into the Folder options dialog.


Go get yourself banned with those pictures. That's flaming.

No it isn't. You apparently don't know the definition of the word flaming. It was off-topic, but nothing more.
Title: Re: Using a for loop to make unlimited folders
Post by: mroilfield on February 17, 2009, 05:27:37 AM
Considering this post started on Valentine's day I guess all the love ran out that day as well.

BatchFileCommand,

Having a signature that says you can hack EBAY doesn't really instill confidence in others when you say this isn't for anything bad.
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 17, 2009, 06:17:39 AM
Having a signature that says you can hack EBAY doesn't really instill confidence in others when you say this isn't for anything bad.


Oh, you actually took that seriously? Hm, I thought no one would.
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 17, 2009, 06:26:56 AM
Dias is a know it all, but only where applicable.

Thanks for the words after the comma  :)
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 17, 2009, 09:12:49 AM
Dias is a know it all, but only where applicable.

Thanks for the words after the comma  :)

Yes, and for all intents and purposes applicable generally means 99% of the time. the 1% you don't know I'm sure you'll readily admit, unlike our friend BFC, who knows very little and yet will jump into any discussion as if it's his domain.

lol, like when somebody listed a VB program and he claimed it needed to use echo.... OMG that was hilarious....
Title: Re: Using a for loop to make unlimited folders
Post by: Dias de verano on February 17, 2009, 12:09:56 PM
the 1% you don't know I'm sure you'll readily admit, unlike our friend BFC, who knows very little and yet will jump into any discussion as if it's his domain.

If I don't know I generally don't bother posting, unlike some people, as I agree with the dictum of the philosopher Ludwig Wittgenstein, who wrote ""Whereof one cannot speak, thereof one must be silent."
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 17, 2009, 12:35:46 PM
Ahh, that's a good strategy, since it avoids the whole awkward stage where you get corrected- a stage BFC seems to treasure.
Title: Re: Using a for loop to make unlimited folders
Post by: computeruler on February 17, 2009, 05:27:15 PM
lol, like when somebody listed a VB program and he claimed it needed to use echo.... OMG that was hilarious....

HAHAHAHHAHAHHHHA!!! Even I know thats not right!
Title: Re: Using a for loop to make unlimited folders
Post by: BatchFileCommand on February 17, 2009, 05:51:29 PM
lol, like when somebody listed a VB program and he claimed it needed to use echo.... OMG that was hilarious....

HAHAHAHHAHAHHHHA!!! Even I know thats not right!



Okay, that's retarded. I almost don't know anything about VB. But I do know that.
Title: Re: Using a for loop to make unlimited folders
Post by: BC_Programmer on February 17, 2009, 05:58:29 PM
obviously not.

Posted here, after DevCom posted the help page from his Choice program:

http://www.computerhope.com/forum/index.php/topic,74243.0.html


ERROR! ERROR! ERROR!

You need an echo before everything that batch file.


The fact that you could mistake a help screen, without a single actual command, for a batch file is simply sad.