Walking through the filesNow 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...
|