RE: Recursive Directory Listing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Joe Schaeffer [mailto:dubelclique@xxxxxxxxx]
> Sent: Tuesday, November 04, 2008 8:56 AM
> To: Jim Lucas
> Cc: php-general@xxxxxxxxxxxxx
> Subject: Re:  Recursive Directory Listing
> 
> > <?php
> > $dir = '.';
> > function displayDir($dir='.') {
> >        $show = FALSE;
> >        $results = glob($dir.'/*');
> >        foreach ( $results AS $entry ) {
> >                if ( is_dir($entry) && !in_array($entry, array('.',
> '..')) ) {
> >                        $dirs[] = $entry;
> >                        $show = TRUE;
> >                }
> >        }
> >        if ( $show ) {
> >                echo '<ul>';
> >                foreach ( $dirs AS $entry ) {
> >                        echo '<li>', basename($entry);
> >                        displayDir($entry);
> >                        echo '</li>';
> >                }
> >                echo '</ul>';
> >        }
> > }
> > displayDir($dir);
> > ?>
> 
> Excellent, Jim. Thanks very much for your help.
> 
> At the risk of straying too far from the original
> subject/call-for-help, is there a way to flag the *first* time the
> function runs through a <ul> creation? Though my design doesn't call
> for it now, I could see the value of styling the first level
> separately than the sub-directories.

Just use a Boolean flag. Set $firstUL to true before your loop starts,
then false after your loop's first iteration (and every subsequent
iteration). Only perform your "special" UL formatting when it's true.

HTH,


Todd Boyd
Web Programmer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux