使用php列出目录中的所有文件夹子文件夹和文件

请给我一个使用php列出目录中所有文件夹,子文件夹,文件的解决方案。我的文件夹结构是这样的:


Main Dir

 Dir1

  SubDir1

   File1

   File2

  SubDir2

   File3

   File4

 Dir2

  SubDir3

   File5

   File6

  SubDir4

   File7

   File8

我想获取每个文件夹内所有文件的列表。


php中有任何shell脚本命令吗?


喵喵时光机
浏览 831回答 3
3回答

泛舟湖上清波郎朗

function listFolderFiles($dir){&nbsp; &nbsp; $ffs = scandir($dir);&nbsp; &nbsp; unset($ffs[array_search('.', $ffs, true)]);&nbsp; &nbsp; unset($ffs[array_search('..', $ffs, true)]);&nbsp; &nbsp; // prevent empty ordered elements&nbsp; &nbsp; if (count($ffs) < 1)&nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; echo '<ol>';&nbsp; &nbsp; foreach($ffs as $ff){&nbsp; &nbsp; &nbsp; &nbsp; echo '<li>'.$ff;&nbsp; &nbsp; &nbsp; &nbsp; if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);&nbsp; &nbsp; &nbsp; &nbsp; echo '</li>';&nbsp; &nbsp; }&nbsp; &nbsp; echo '</ol>';}listFolderFiles('Main Dir');
打开App,查看更多内容
随时随地看视频慕课网APP