rendered paste body<?php function scandir1($dir) { $dirlist = opendir($dir); // open the directory while ($file = readdir ($dirlist)) // while file = readdir { if ($file != '.' && $file != '..') //if file = . current dir or .. back 2 dirs { $newpath = $dir.'/'.$file; $level = explode('/',$newpath); //split newpath into array so /home/mark becomes array[0]=>home array[1=>mark if (is_dir($newpath)) { echo "\nDirectory found at \n + $newpath"; $content=scandir1($newpath); }else{ //if newpath is not dir $mod_array[] = array( 'level'=>count($level)-1, 'path'=>$newpath, 'name'=>end($level), 'kind'=>'file', ); } } } closedir($dirlist); return $mod_array; } echo '<pre>'; print_r(scandir1('.')); echo '</pre>';?>