1.3.1Class Directory

Special iterator to access directory listings.

Class Directory( dirname )
dirname A relative or absolute path to a directory
IoError on failure.

The Directory class allow to iterate through the contents of a local file directory.

The caller should repeatedly call the read() method until nil is returned. In case an error is raised, the error() method may be called to get informations on the cause that raised the error.

After the read is complete, the caller should call close() to free the resources associated with the object. The garbage collector will eventually take care of it, but it is better to close the object as soon as possible.

closeCloses the directory object.
descendDescends into subdirectories, iteratively calling a function.
errorReturns the last system error code that the directory operation causes.
readReturns the next entry in the directory.



Closes the directory object.


This method should be called when the item is not needed anymore to free system resources.

However, the directory listing is closed at garbage collecting.


Descends into subdirectories, iteratively calling a function.

Directory.descend( [dfunc],[ffunc] )
dfunc Function to be called upon directories.
ffunc Function to be called upon files.

This function calls iteratively a function on directory entries. If an entry is detected to be a directory, it is passed to dfunc as the only parameter. If ffunc is also provided, then it will receive all the non-directory entries. Entries coresponding to the current directory and the parent directory will never be sent to the handler functions.

Note: The parameters for dfunc and ffunc will always be relative to the directory on which this object has been created.

Retunring an out of band 0, any of the callbacks involved may stop the processing and return immediately. An out of band 1 will skip the currently processed item and proceed. The dfunc handler is called before descending into the found subdirectory; this gives the handlers the chance to skip directories or interrupt the search.

Note: After a complete descend, this directory will be closed and won't be usable anymore.


Returns the last system error code that the directory operation causes.

ReturnA system error code.

The error code may be rendered into a string using the systemErrorDescription function.


Returns the next entry in the directory.

ReturnA string representing the next entry, or oob(0) when no new entries are left.

The usage is

   dir =  Directory( "." )
   while entry = dir.read(): > entry


   dir = Directory( "." )
   for entry in dir.read: > entry
Made with http://www.falconpl.org