Class DirectoryIterator

DirectoryIterator
Classes extended from DirectoryIterator:
Location: Program_Root/iterator/DirectoryIterator.php
Class DirectoryIterator provides a simple iterator for traversing the
 files in a directory.
 

On construction a directory name must be passed, and the contents can then be iterated over like any other Iterator. If the iterator is used normally (from front to back completely), the internal directory pointer is closed automatically when the end of the directory is reached. If the standard iteration loop is not completed, the directory pointer should be closed explicitly by calling close() on the iterator. For example:

   $closed =  true;
   $it     =& new DirectoryIterator('/home/user');
   for ( ; $it->isValid(); $it->next())
   {
       $file =& $it->getCurrent();
       if ($file == 'stopfile.txt')
       {
           $closed = false;
           break;
       }
       echo $file . "\n";
   }
   if (!$closed)
   {
       $it->close();
   }
 

If the directory to be read can't be opened for one reason or another, this class will not fail. Instead, it will simply 'iterate over nothing'. Of course, PHP will still log warnings and/or errors somewhere, depending on how this is configured.


Class Variable Summary


Inherited Class Variable Summary


Method Summary


Inherited Method Summary


Variable Detail


Method Detail