ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Walking through server folders and files --> Part 3

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
184 active users
3167 visitors today
3081 pages today
(only part of today)
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

Walking through the files

Now we want to walk through all the files in the folder. The Folder object has a collection called Files that contains this list, so we start by creating an Enumerator that can walk this collection:

// create enumerator (like FOR EACH in VBScript)
var eFile = new Enumerator ( oFolder.Files );

// walk through all the files in this folder
while ( !eFile.atEnd ( ) )
{
   var oFile = eFile.item ( );

   // notify that we have a new file
   fFileNotify ( oFile, nLevel );

   eFile.moveNext ( );
}

Using an Enumerator is quite simple once you've seen an example. While the atEnd( ) method returns false, keep looping by calling the moveNext( ) method.

Enumerators have an item( ) method which returns the current item from the collection, in this case a File object.

As before, we pass this object to the passed in function, fFileNotify.

Side-bar: Have you noticed how I prefix my variables with a lowercase character? So-called "Hungarian notation", named after Hungarian and Microsoft developer Charles Simonyi, the idea is to allow developers to recognize what type of variable it is.

I use a simpler modified version, but that's why you'll see variables such as sData (for a string), nLevel (for an integer number), oFile (for an object) or fFilenotify (for a function).

Part 4: Walking through the folders...

Featured sponsor
My favorite resources

Selling products online - read how James does it now



I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!