Directory Iteration With DirectoryIterator() In PHP 5

Friday, September 26, 2008 - 10:53

The normal way of looping through a directory is to get a handle on the directory, then go through each item, making sure that the file is readable and is not "." or ".." before doing something with the file. Because this is done a lot the DirectoryIterator() object was created in PHP5 to simplify this process.

The constructor of the DirectoryIterator() object takes a single parameter, this is the path of the directory that is to be iterated over.