Page 1 of 1

listing folders and files issue

Posted: Mon Jun 12, 2006 9:50 am
by itsmani1
I am using following code for lising all files and folders in a specfic folder or directory.

Code: Select all

<?
function read_dir($dir) {
   $array = array();
   $d = dir($dir);
   while (false !== ($entry = $d->read())) {
       if($entry!='.' && $entry!='..') {
           $entry = $dir.'/'.$entry;
           if(is_dir($entry)) {
               $array[] = $entry;
               $array = array_merge($array, read_dir($entry));
           } else {
               $array[] = $entry;
           }
       }
   }
   $d->close();
   return $array;
}

$abc = array();
$abc = read_dir("abc");
?>
i want to list folders and files in "abc" only, and then when i pass abc's child folder it should show me its files and folders.

how can i stop it when it has shown me foders and files in abc?

Posted: Mon Jun 12, 2006 11:41 am
by feyd
remove the recursion.

Posted: Thu Jun 15, 2006 12:31 am
by itsmani1
well, its done. but now the list is in aphabetical order, but i want to list all directories, but i want to list directories first and then files .

??

Posted: Thu Jun 15, 2006 1:17 am
by feyd
Store directories into an array, files in another. Sort each then combine them.