Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Creating and deleting directories

Will show you the basics of creating several directories named 1, 2, 3... or using a prefix like dir1, dir2, dir3. Also shows you how to delete an empty dir.

On Saturday, March 27th 2004 at 09:37 AM
By Andrew Pociu (View Profile)
****-   (Rated 3.7 with 18 votes)
Contextual Ads
More Visual Basic Resources
Advertisement

The most importand commands that we use in this tutorial are 'MkDir' and 'RmDir', that is 'make a directory' and 'remove a directory'.
For enhancing the program, we use a while loop to create several directories following a pattern.


First, download the code from here.


You probably already know the Visual Basic loops and other elementary things about Visual Basic, so I'm not going to insist on analyzing the small code.

The main action takes place when we click the cmdMakeDir button:


Dim i As Integer
i = 1
While i <= txtNum.Text
Dim dir As String
dir = txtPath.Text & i
MkDir dir
i = i + 1
Wend




Dim i As Integer
i = 1


We create a variable i that will be used for looping.




While i <= txtNum.Text


We test to see if i is smaller than number typed in the txtNum that shows us how many directories we want to create.




Dim dir As String
dir = txtPath.Text & i


We concatenate the string in txtPath.Text (the path where we want the directories to be created) with the number that the variable i currently holds.


Warning: Be sure the directory where you want the other directories to be created exists, else you will get an ugly error.


Here is the trick:
We suppose we have a directory named temp in the root of C:\ (C:\temp).
If in the txtPath we type C:\temp\ (notice the trailing slash), we will have directories 1, 2, 3... (till we reach the number typed in the txtNum) created in the folder C:\temp.
The path for the directories will be:

C:\temp\1
C:\temp\2
C:\temp\3

... and so on.

On the other hand, if we type C:\temp (notice there is no trailing slash), we will have the directories created in the root of C:\ with the prefix 'temp', like this:

C:\temp1
C:\temp2
C:\temp3

... and so on.
This is because when we concatenate using:


dir = txtPath.Text & i


we actually have dir = C:\temp1 because we didn't add the trailing slash.




MkDir dir


Then we create the actually directory...


i = i + 1


Increment the variable so the loop isn't endless...


Wend

And close the loop.

This is a basic way to create several folders using a prefix. From now on it's easy to create directories using a prefix or a suffix, or both. Or following a pattern.


There is no need to explain the rest of the code in the program, like the one for deleting a directory because it's very simple.
Remember! RmDir only works on empty directories
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by ANIK on Friday, April 13th 2007 at 06:52 AM

GR8

by emina buchi on Monday, March 23rd 2009 at 06:27 AM

thanx alot i find this tutorial very intereting want more

by jo black on Sunday, October 4th 2009 at 02:47 PM

good tutorial but must you do this in half of the screen?


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs Visual Basic Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources