View Single Post
Old 09-10-2012, 06:54 AM   #7 (permalink)
scottchu
The Visitor
 
Join Date: Sep 2012
Posts: 2
Thanks: 0
scottchu is on a distinguished road
Default Your code skips all files

Quote:
Originally Posted by ETbyrne View Post
OK, here's a sweet little function I made that does exactly what you need:

PHP Code:
function glob_recursive($dir)
{
    static 
$g = array();
    
    foreach(
glob($dir,GLOB_ONLYDIR) as $i=>$k)
    {
        
$g[] = $k;
        
glob_recursive($k.'/*');
    }
    
    return 
$g;

And use like so:

PHP Code:
print_r(glob_recursive('dingo/*')); 
The only problem is, you can't use it twice. I'll let you figure out how to fix that though.
Your code skips all files and will always return an empty array if there's no subfolders initially. A revised codes could be:

PHP Code:
function glob_recursive($dir)
{
    static 
$g = array();
    
    foreach(
glob($dir) as $i=>$k)
    {
        if (
is_dir($k))
            
glob_recursive($k.'/*');
        else
            
$g[] = $k;
    }
    return 
$g;
}

// Show human-readable dump of array contents
echo nl2br(print_r(glob_recursive('dingo/*'),true)); 
scottchu is offline  
Reply With Quote