DirectoryIteratorClasses extended from DirectoryIterator:
ClassDirectoryIteratorprovides 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 callingclose()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.
iteratorJapha 1.0Ryan Gantt
@void close()
String current()
boolean hasNext()
boolean isValid()
void next()
String readFile()
void reset()
void __construct()
Close the internal directory pointer. This method must be called if the iteration is stopped before it is completed (that is: before the end of the directory is reached).
public
Get the current file
the name of the current file
Returns true iff there is another file in the directory
true iff there is another file in the directory
public
Determine if we are at the end of the directory
true iff the current file is actually a file
@
public
Move to the next file
public
Read a file from the directory
the name of the current file (not . or .. )
@
private
Rewind to the beginning of the directory
@
public
Constructor... Creates a new iterator
public