note 79778 added to ref.spl

From: Date: Wed, 12 Dec 2007 14:57:32 +0000
Subject: note 79778 added to ref.spl
Groups: php.notes 
Request: Send a blank email to php-notes+get-133390@lists.php.net to get a copy of this message
My favorite recursive iteration solution: <?php $dir_iter = new RecursiveDirectoryIterator($root_dir, 0); $all_iter = new RecursiveIteratorIterator($dir_iter); foreach ($all_iter as $abs_path => $info) { // your code here } ?> You can't just loop on $dir_iter, because it will return the exact same results as the plain DirectoryIterator. It is the RecursiveIteratorIterator that iterates over the children of the RecursiveDirectoryIterator if they're present. Passing 0 as the flags to the RecursiveDirectoryIterator means that $info will be a RecursiveDirectoryIterator object, and then you can use the getSubPath() and getSubPathname() methods to find the directory (or directory and filename, resp.) relative to $root_dir. By default, $info is a SplFileInfo object instead, which only knows its full pathname, including $root_dir. The RecursiveDirectoryIterator extends SplFileInfo, so all those methods are still available. ---- Server IP: 64.71.164.2 Probable Submitter: 69.205.153.76 ---- Manual Page -- http://www.php.net/manual/en/ref.spl.php Edit -- https://master.php.net/note/edit/79778 Del: integrated -- https://master.php.net/note/delete/79778/integrated Del: useless -- https://master.php.net/note/delete/79778/useless Del: bad code -- https://master.php.net/note/delete/79778/bad+code Del: spam -- https://master.php.net/note/delete/79778/spam Del: non-english -- https://master.php.net/note/delete/79778/non-english Del: in docs -- https://master.php.net/note/delete/79778/in+docs Del: other reasons-- https://master.php.net/note/delete/79778 Reject -- https://master.php.net/note/reject/79778 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133390) next »