【发布时间】:2014-02-14 14:28:44
【问题描述】:
我一直在尝试打印列表中的文件,同时获取文件、文件夹和子文件夹。 我可以把所有东西都拿出来,但我想先显示文件夹。 有没有办法做到这一点?
到目前为止我的代码:
function getFiles($path) {
foreach (new DirectoryIterator($path) as $file) {
if($file->isDot()) continue;
if($file->isDir())
echo "<li class='folder'>\n";
else
echo "<li>\n";
echo "<a href='#'>" . $file->getFilename() . "</a>\n";
if ($file->isDir()) {
echo "<ul>\n";
getFiles($file->getPathname());
echo "</ul>\n";
}
echo "</li>\n";
}
}
希望你能帮帮我!
【问题讨论】: