[Repost] Recursive Directory Iterator

From: Date: Mon, 20 Dec 2004 17:02:20 +0000
Subject: [Repost] Recursive Directory Iterator
Groups: php.general 
Request: Send a blank email to php-general+get-204722@lists.php.net to get a copy of this message
This is my first time trying out the SPL iterators. Im trying to figure out how to recursively move over a directory. With the code that I've provided 1. Is this the correct way to use it? Im using recursive functions to go deep. I thought, that the class would do that for me somehow... 2. As it stands, it doesn't report the correct directory structure. For example, if I had a directory in the root with another directory under it, the second directory doesnt get echoed. Thanks ------ dirr('.'); function dirr($dir) { $dir = new RecursiveDirectoryIterator($dir); foreach($dir as $foo) {
       echo $foo->getPathname() . '<br />';
       if ($foo->hasChildren())
       {
           $bar = $foo->getChildren();
           foreach($bar as $foo2)
           {
                if ($foo2->hasChildren())
                {
                    dirr($foo2->getPathname());
                }
                else
                {
                    echo $foo2->getPathName() . '<br />';
                }
           }
       }
} }

« previous php.general (#204722) next »