Home > Backend Development > PHP Tutorial > PHP lists the implementation code of all subdirectories in the directory

PHP lists the implementation code of all subdirectories in the directory

WBOY
Release: 2016-07-25 08:56:13
Original
1032 people have browsed it
  1. /**

  2. * Remove all subdirectories of the specified directory
  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. //Call to get all subdirectories in the directory and loop through.

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

Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template