How to make A-Z folders in specified location 07-16-2013, 06:14 PM
#1
Hey there,
In this tutorial I'm going to show you how to make folders named A-Z in a specified location. The user will have the option to set the destination location and say if the folders should be deleted or created. That why you can also easily get rid of the folders if you don't want them or placed them in the wrong location.
1. We don't want echoing
There are many reasons to turn of echoing in command line programming. The main reason for us is that it makes the program more easy to read. If you don't turn echoing off the command prompt will print out all commands that are being executed. To turn off echoing we use this code:
![[Image: HWnZMUf.png]](http://i.imgur.com/HWnZMUf.png)
This line is usually the first one you find in batch programs, because there's usually no reason to show any of the commands other than their output.
2. Organisation
Even with such an easy language and small program I feel that organisation in the code is very important.
We are going to create 4 sort of 'menus' inside our code and explain what they do.
![[Image: 4vehhUf.png]](http://i.imgur.com/4vehhUf.png)
What you must always remember is that the code is being read from top to bottom, that's why you should always put the code for closing at the end.
What is your desired location? The galaxy of dreams...
We are now going to do 2 simple things. First we are going to create a set variable, that's a variable equal to the user's input. Second we are going to create folders named A-Z in that location that was given. All of this will happen within
tart.
First we will set an environment variable, these only remain within the current session. To access the environment variable you type the name of the variable within percent marks. So if you named your variable VAR1 you would write %VAR1% to access/display it.
This is what you will write:
![[Image: kj7i.png]](http://img832.imageshack.us/img832/957/kj7i.png)
"set" is obviously the command here. "/p" specifies for a user input. "Location" is obviously the name of the variable. The "=Desired Location for the folders: " part is the text that will display. You can also leave this empty to display nothing but telling the user what to do is much more clear. Be sure to add a whitespace after the colon otherwise it will look messy when the user starts typing the desired location.
The next thing we write is this:
![[Image: 3s8.png]](http://img194.imageshack.us/img194/3627/3s8.png)
We are doing a lot of things here, let me explain.
We are using the for command to perform a command several times. Then we create a parameter name, I called it %%a with the a standing for "all" (a-z, all our letters). Then we specify the list of items, so "in (a....z)" will make a sort of 'list' with items of A till Z. After that all we specify our command with "do md "%location%\%%a"". The command md stands for 'make directory'.
Notice how we access the %location% variable in this code? We also use the %%a parameter again to acces the item. It will now md (make directory) for every item in %%a, which is A untill Z. So it will basically perform the make directory command for every item in our parameter. Nifty little code eh?
3. Oh noes, wrong location?
We are now going to move to
top. Remember, I said that it reads from top to bottom so there is no need for us to add anymore code to
tart to specify that we want to go to
top because it's right under
tart.
First we use one of the most basic codes:
cls
This stands for 'clear screen' and it will wipe any text off the console.
Next we are going to display some text to tell the user what is going on.
![[Image: d462.png]](http://img28.imageshack.us/img28/3021/d462.png)
What we are now going to use is called a 'choice menu'.
The user will have the 2 default options which are 'Yes' and 'No'.
Whatever the user chooses is what deletes the folders or not.
You are going to write:
![[Image: yko.png]](http://img844.imageshack.us/img844/1310/yko.png)
The "/c YN" specifies the choices the user gets, which are Y and N. (obviously Y equals Yes and N equals No)
The "/m "Do you want to remove the folders?"" will print out our desired text.
Now you will write this:
![[Image: Cb1QiW1.png]](http://i.imgur.com/Cb1QiW1.png)
I am not going to explain errorlevels and I hope that I don't need to explain the goto command.
Basically if the user chooses Y it will throw an errorlevel of 1 and if the user choosed N it will throw an errorlevel of 2.
4. Please master! Please... ! Don't remove me from this world!
Now we are going to code the :remove part. It's pretty easy, we are going to use the 'for' command again. This is what you will type, it's pretty similar:
![[Image: c0gb.png]](http://img836.imageshack.us/img836/3180/c0gb.png)
What it does is again do the command again for each item in %%a which is still A-Z. Now write cls again to clear the console of text.
Now echo out some text to tell the user it is done:
![[Image: 6a1g.png]](http://img607.imageshack.us/img607/700/6a1g.png)
Next you use the 'pause' command to pause the console until a key is pressed. We add >null after the command to make sure no text for it is displayed. You can just write pause if you want to display automatic text for the pause command.
![[Image: ahBtcqZ.png]](http://i.imgur.com/ahBtcqZ.png)
5. Time to close the gates.
Closing this application is the easiest. All we have to do is write this below :exit
exit
Done!
Now all you have to do is save the file with the .bat extension and it's ready to go!
Full code
Don't forget to rep me if you think I deserve an apple
--
Platinum shines, it's not gold.
-Platinum.
In this tutorial I'm going to show you how to make folders named A-Z in a specified location. The user will have the option to set the destination location and say if the folders should be deleted or created. That why you can also easily get rid of the folders if you don't want them or placed them in the wrong location.
1. We don't want echoing
There are many reasons to turn of echoing in command line programming. The main reason for us is that it makes the program more easy to read. If you don't turn echoing off the command prompt will print out all commands that are being executed. To turn off echoing we use this code:
![[Image: HWnZMUf.png]](http://i.imgur.com/HWnZMUf.png)
This line is usually the first one you find in batch programs, because there's usually no reason to show any of the commands other than their output.
2. Organisation
Even with such an easy language and small program I feel that organisation in the code is very important.
We are going to create 4 sort of 'menus' inside our code and explain what they do.
![[Image: 4vehhUf.png]](http://i.imgur.com/4vehhUf.png)
What you must always remember is that the code is being read from top to bottom, that's why you should always put the code for closing at the end.
What is your desired location? The galaxy of dreams...
We are now going to do 2 simple things. First we are going to create a set variable, that's a variable equal to the user's input. Second we are going to create folders named A-Z in that location that was given. All of this will happen within

First we will set an environment variable, these only remain within the current session. To access the environment variable you type the name of the variable within percent marks. So if you named your variable VAR1 you would write %VAR1% to access/display it.
This is what you will write:
![[Image: kj7i.png]](http://img832.imageshack.us/img832/957/kj7i.png)
"set" is obviously the command here. "/p" specifies for a user input. "Location" is obviously the name of the variable. The "=Desired Location for the folders: " part is the text that will display. You can also leave this empty to display nothing but telling the user what to do is much more clear. Be sure to add a whitespace after the colon otherwise it will look messy when the user starts typing the desired location.
The next thing we write is this:
![[Image: 3s8.png]](http://img194.imageshack.us/img194/3627/3s8.png)
We are doing a lot of things here, let me explain.
We are using the for command to perform a command several times. Then we create a parameter name, I called it %%a with the a standing for "all" (a-z, all our letters). Then we specify the list of items, so "in (a....z)" will make a sort of 'list' with items of A till Z. After that all we specify our command with "do md "%location%\%%a"". The command md stands for 'make directory'.
Notice how we access the %location% variable in this code? We also use the %%a parameter again to acces the item. It will now md (make directory) for every item in %%a, which is A untill Z. So it will basically perform the make directory command for every item in our parameter. Nifty little code eh?
3. Oh noes, wrong location?
We are now going to move to




First we use one of the most basic codes:
cls
This stands for 'clear screen' and it will wipe any text off the console.
Next we are going to display some text to tell the user what is going on.
![[Image: d462.png]](http://img28.imageshack.us/img28/3021/d462.png)
What we are now going to use is called a 'choice menu'.
The user will have the 2 default options which are 'Yes' and 'No'.
Whatever the user chooses is what deletes the folders or not.
You are going to write:
![[Image: yko.png]](http://img844.imageshack.us/img844/1310/yko.png)
The "/c YN" specifies the choices the user gets, which are Y and N. (obviously Y equals Yes and N equals No)
The "/m "Do you want to remove the folders?"" will print out our desired text.
Now you will write this:
![[Image: Cb1QiW1.png]](http://i.imgur.com/Cb1QiW1.png)
I am not going to explain errorlevels and I hope that I don't need to explain the goto command.
Basically if the user chooses Y it will throw an errorlevel of 1 and if the user choosed N it will throw an errorlevel of 2.
4. Please master! Please... ! Don't remove me from this world!
Now we are going to code the :remove part. It's pretty easy, we are going to use the 'for' command again. This is what you will type, it's pretty similar:
![[Image: c0gb.png]](http://img836.imageshack.us/img836/3180/c0gb.png)
What it does is again do the command again for each item in %%a which is still A-Z. Now write cls again to clear the console of text.
Now echo out some text to tell the user it is done:
![[Image: 6a1g.png]](http://img607.imageshack.us/img607/700/6a1g.png)
Next you use the 'pause' command to pause the console until a key is pressed. We add >null after the command to make sure no text for it is displayed. You can just write pause if you want to display automatic text for the pause command.
![[Image: ahBtcqZ.png]](http://i.imgur.com/ahBtcqZ.png)
5. Time to close the gates.
Closing this application is the easiest. All we have to do is write this below :exit
exit
Done!
Now all you have to do is save the file with the .bat extension and it's ready to go!
Full code
Spoiler:
Don't forget to rep me if you think I deserve an apple

--
Platinum shines, it's not gold.
-Platinum.