function getCatalogStruct($path, array &$list) {
$d = dir($path);
while (false !== ($entry = $d->read())) {
if (is_file($path."/".$entry)) {
$list[] = $entry;
}
if (is_dir($path."/".$entry) && $entry !== "." && $entry !== "..") {
$list[$entry] = array();
getCatalogStruct($path."/".$entry."/", $list[$entry]);
}
}
$d->close();
}
$catalogStruct = array();
$path = "./debugMsg/";
getCatalogStruct($path, $catalogStruct);
echo "<pre>";
print_r($catalogStruct);
echo "</pre>";
Вот такая структурка на выходе:
Array ( [dir1] => Array ( [subdir1] => Array ( ) [0] => subTestFile1.txt [1] => subTestFile2.txt ) [dir2] => Array ( [0] => subTestFile2.txt ) [0] => testFile1.txt [1] => testFile2.txt [2] => testFile3.txt [3] => testFile4.txt )