get directory paths recursively using SPL ... was Re: [PHP] Am I supposed to be using SPL?

From: Date: Wed, 31 May 2006 20:54:27 +0000
Subject: get directory paths recursively using SPL ... was Re: [PHP] Am I supposed to be using SPL?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-237169@lists.php.net to get a copy of this message
Jochem Maas wrote:
also take a look here: http://www.wiki.cc/php/RecursiveDirectoryIterator yes it's meant to be used, yes you can use it in production BUT your a little on the bleeding edge (not very many people using it full on) AND the whole of SPL is still a little in flex (as is php5->php6 in general) so that you may be forced, occasionally, to adapt your code to changes (e.g. constants that were formally used in SPL are now class constants.)
Wow, this is some magical stuff. Here is my function in case it's of use: //---------------------------------------------------------------------- /**
    * Magical SPL code to recursively list files in a directory
    */
public static function get_paths_recursive($start_path) {
       $paths = array();
       $rdi = new RecursiveDirectoryIterator($start_path);
       foreach (new RecursiveIteratorIterator($rdi) as $path) {
           array_push($paths, (string) $path);
       }
       return $paths;
} //---------------------------------------------------------------------- This iterates over objects like arrays, casts objects as strings, and iterates iterators. All sorts of fun and joy enough to make your head spin. Seems to work, though ;-) Thanks for the wiki doc link, Jochem. Dante

« previous php.general (#237169) next »