Главная | Руководство по MySQL | MySQL Manual | Документация к HTTP серверу Apache | Apache HTTP Server Documentation | downloads | faq

искать  Язык: Английский

The RecursiveDirectoryIterator class



Class synopsis

RecursiveDirectoryIterator extends DirectoryIterator implements Traversable , Iterator , RecursiveIterator {
/* Methods */
object getChildren ( void )
bool hasChildren ([ bool $allow_links ] )
string key ( void )
void next ( void )
void rewind ( void )
/* Inherits */
DirectoryIterator DirectoryIterator::current ( void )
string DirectoryIterator::getPath ( void )
string DirectoryIterator::getType ( void )
bool DirectoryIterator::isDir ( void )
bool DirectoryIterator::isDot ( void )
string DirectoryIterator::key ( void )
void DirectoryIterator::next ( void )
string DirectoryIterator::valid ( void )


User Contributed Notes
09-Apr-2010 07:05
If you would like to get, say, all the *.php files in your project folder, recursively, you could use the following:


= new RecursiveDirectoryIterator('path/to/project/');
$Iterator = new RecursiveIteratorIterator($Directory);
$Regex = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);


$Regex will contain a single index array for each PHP file.
15-Jul-2009 08:57
Usage example:
To see all the files, and count the space usage:

=new RecursiveDirectoryIterator("/path/");

foreach (new
RecursiveIteratorIterator($ite) as $filename=>$cur) {
"$filename => $filesize\n";

"Total: $nbfiles files, $bytestotal bytes\n";
Justin Deltener
10-Jun-2009 04:45
If you don't get a fully recursive listing, remember to check your permissions on the folders. I just spent 2 hours to find out my root folder didn't have +x on it. I did a chmod g+x and now get a full listing. Oddly, I was able to get a listing of files/folders one level UNDER that folder, but nothing beyond that point which was cause for the confusion.
alvaro at demogracia dot com
18-Sep-2008 03:15
Usage example:


= realpath('/etc');

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
$objects as $name => $object){


This prints a list of all files and directories under $path (including $path ifself). If you want to omit directories, remove the RecursiveIteratorIterator::SELF_FIRST part.

credits | contact