我有我的“/模板”文件夹中的以下文件和文件夹:PHP SCANDIR排序第一单文件,那么文件夹和子文件夹
/templates/folder/contact.html
/templates/folder/index.html
/templates/folder/search.html
/templates/index.html
/templates/music.html
/templates/path/index.html
/templates/path/test.html
/templates/video.html
现在我想要得到的名单第一排序的单个文件,
然后将文件夹和子文件夹,我的意思是:
/index.html
/music.html
/video.html
/folder/contact.html
/folder/index.html
/folder/search.html
/path/index.html
/path/test.html
,我使用这个代码,但我无法弄清楚如何将它们的顺序进行排序。请帮助
<?php
function listFolderFiles($dir, $parent = ''){
$ffs = scandir($dir);
echo '<ol style="padding:0;">';
foreach($ffs as $ff){
if($ff != '.' && $ff != '..'){
echo '<li>'.$parent.'/'.$ff;
if(is_dir($dir.'/'.$ff)){
listFolderFiles($dir.'/'.$ff, $ff);
}
echo '</li>';
}
}
echo '</ol>';
}
listFolderFiles('templates');
?>
请注意:实际上这个代码也是一次输出子文件夹为“空”,例如, /folder
和子文件夹里面的内容,而最初的斜线:folder/contact.html
,但我需要有一个像最初的斜线:/folder/contact.html
并删除“空”子文件夹