TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   List as array and modify the input (http://www.talkphp.com/general/5241-list-array-modify-input.html)

Peuplarchie 01-30-2010 09:28 PM

List as array and modify the input
 
Good day to you all,
here I have a recursive directory lister that puts everything into an array.

Here is the code:

PHP Code:



<?
function getDirectory($path '.'$ignore '') {
    
$dirTree = array ();
    
$dirTreeTemp = array ();
    
$ignore[] = '.';
    
$ignore[] = '..';

    
$dh = @opendir($path);

    while (
false !== ($file readdir($dh))) {

        if (!
in_array($file$ignore)) {
            if (!
is_dir("$path/$file")) {
                
                
$dirTree["$path"][] = $file;
                
            } else {
                
                
$dirTreeTemp getDirectory("$path/$file"$ignore);
                if (
is_array($dirTreeTemp))$dirTree array_merge($dirTree$dirTreeTemp);
            }
        }
    }
    
closedir($dh);
    
    return 
$dirTree;
}

$ignore = array('.htaccess''error_log''cgi-bin''php.ini''.ftpquota');

$dirTree getDirectory('Photos'$ignore);
?>
<pre>
    <?
    print_r
($dirTree);
    
?>
</pre>


My question is how can I keep the same array and without looping again through the directories again list only the folder ?

If i can, how can I also list a text only the folder that does have folder in them and as a link the one that as files.

So when a link is press I can list the array under that folder

Thanks!


All times are GMT. The time now is 06:33 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0