I need to get all the folders and files from a folder recursively in alphabetical order (folders first, files after) 

Is there an implemented PHP function which caters for this?

I have this function:

```
function dir_tree($dir) {
   $path = '';
   $stack[] = $dir;
   while ($stack) {
       $thisdir = array_pop($stack);
       if ($dircont = scandir($thisdir)) {
           $i=0;
           while (isset($dircont[$i])) {
               if ($dircont[$i] !== '.' && $dircont[$i] !== '..' && $dircont[$i] !== '.svn') {
                   $current_file = "{$thisdir}/{$dircont[$i]}";
                   if (is_file($current_file)) {
                       $path[] = "{$thisdir}/{$dircont[$i]}";
                   } elseif (is_dir($current_file)) {
                        $path[] = "{$thisdir}/{$dircont[$i]}";
                       $stack[] = $current_file;
                   }
               }
               $i++;
           }
       }
   }
   return $path;
}

```

I have sorted the array and printed it like so:

```
$filesArray = dir_tree("myDir");
natsort($filesArray);

foreach ($filesArray as $file) {
    echo "$file<br/>";
}

```

What I need is to know when a new sub directory is found, so I can add some spaces to print it in a directory like structure instead of just a list.

Any help?

Many thanks