Home > Backend Development > PHP Tutorial > PHP function to list all subdirectories in a directory

PHP function to list all subdirectories in a directory

WBOY
Release: 2016-07-25 08:45:16
Original
888 people have browsed it

The following function lists all subdirectories in a directory:

  1. function listdir($dir){
  2. if ($handle = opendir($dir)){
  3. $output = array() ;
  4. while (false !== ($item = readdir($handle))){
  5. if (is_dir($dir.'/'.$item) and $item != "." and $item != ". ."){
  6. $output[] = $dir.'/'.$item;
  7. $output = array_merge($output, ListDescendantDirectories($dir.'/'.$item));
  8. }
  9. }
  10. closedir( $handle);
  11. return $output;
  12. }else{
  13. return false;
  14. }
  15. }
  16. $dirs = listdir('myDirectory');
  17. foreach($dirs as $dir){
  18. echo $dir.'< ;br>';
  19. }
  20. ?>
Copy code

Directory, PHP


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