Home > Backend Development > PHP Tutorial > Function written in PHP to recursively list all files and directories

Function written in PHP to recursively list all files and directories

WBOY
Release: 2016-07-25 09:03:28
Original
901 people have browsed it
  1. /*
  2. Simple directory recursive function
  3. */
  4. function tree($directory)
  5. {
  6. $mydir=dir($directory);
  7. echo "
      ";
    • while($file=$mydir->read()){
    • if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!=".." )){
    • echo "
    • $file
    • ";
    • tree("$directory/ $file");
    • }else{
    • echo "
    • $file
    • ";
    • }
    • }
    • echo "
    ";
  8. $mydir->close();
  9. }
  10. //start the program
  11. echo "

    The directory is pink

    ";
  12. tree(".");
  13. ?>
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