当前位置:Gxlcms > PHP教程 > php列出目录中所有子目录的实现代码

php列出目录中所有子目录的实现代码

时间:2021-07-01 10:21:17 帮助过:17人阅读

  1. /**

  2. * 取出指定目录的所有子目录
  3. * edit: bbs.it-home.org
  4. * 2013/10/9
  5. */
  6. function listdir($dir){
  7. if ($handle = opendir($dir)){
  8. $output = array();
  9. while (false !== ($item = readdir($handle))){
  10. if (is_dir($dir.'/'.$item) and $item != "." and $item != ".."){
  11. $output[] = $dir.'/'.$item;
  12. $output = array_merge($output, ListDescendantDirectories($dir.'/'.$item));
  13. }
  14. }
  15. closedir($handle);
  16. return $output;
  17. }else{
  18. return false;
  19. }
  20. }

  21. //调用,取目录中的所有子目录,循环遍历。

  22. $dirs = listdir('myDirectory');
  23. foreach($dirs as $dir){
  24. echo $dir.'
    ';
  25. }
  26. ?>

人气教程排行