Re: RecursiveDirectoryIterator and foreach
| From: | Ryan Panning | Date: | Mon, 23 Feb 2009 17:27:37 +0000 |
| Subject: | Re: RecursiveDirectoryIterator and foreach | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288689@lists.php.net to get a copy of this message | ||
Nathan Nobbe wrote:
if youre trying to do recursive iteration whereby you 'flatten' the tree structure, drop the RecursiveDirectoryIterator into a RecursiveIteratorIterator (its for iterating over RecursiveIterators), then you dont have to bother w/ calling hasChildren() at all. you probly also want to look at the constructor args, since by default, it only returns leaf nodes. $dir = new RecursiveDirectoryIterator('/path/to/dir'); $itt = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);Hi, thanks for the idea. In my case I do not want to flatten the tree. When there is a sub-directory I make a repeat call to the function/method, there-by calling it for each directory. I'd give you more details but I don't think it'd help with this specific issue.foreach ($itt as $item) { print get_class($item) . "\r\n"; }-nathan