View Single Post
Old 06-13-2007, 11:43 PM   PM User | #6
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
This function does the same thing but is a _LOT_ faster:
PHP Code:
function get_dir_iterative($dir '.'$exclude = array( 'cgi-bin''.''..' ))
{
    
$exclude array_flip($exclude);
    if(!
is_dir($dir))
    {
        return;
    }
    
    
$dh opendir($dir);
    
    if(!
$dh)
    {
        return;
    }

    
$stack = array($dh);
    
$level 0;

    while(
count($stack))
    {
        if(
false !== ( $file readdir$stack[0] ) ) )
        {
            if(!isset(
$exclude[$file]))
            {
                print 
str_repeat(' '$level 4);
                if(
is_dir($dir '/' $file))
                {
                    
$dh opendir($file '/' $dir);
                    if(
$dh)
                    {
                        print 
"<strong>$file</strong><br />\n";
                        
array_unshift($stack$dh);
                        ++
$level;
                    }
                }
                else 
                {
                    
                    print 
"$file<br />\n";
                }
            }
        }
        else 
        {
            
closedir(array_shift($stack));
            --
$level;
        }
    }

__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.

Experience is something you get just after you really need it.
PHP Installation Guide Feedback welcome.
marek_mar is offline   Reply With Quote