[PHP] get directory paths recursively using SPL ... was Re: [PHP] Am I supposed to be using SPL?
by D. Dante Lorenso other posts by this author
May 31 2006 1:55PM messages near this date
Re: [PHP] Am I supposed to be using SPL?
|
[PHP] ob_flush() problems
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
D. Dante Lorenso
Kevin Waterson
Richard Lynch
Kevin Waterson
Jochem Maas
Jochem Maas
D. Dante Lorenso
|