Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
1343 active users
14409 visitors today
17951 pages today
(only part of today)
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

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

Tiki Statues - Tiki Masks - Tiki Totems



Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?