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
WBOYOriginal
2016-07-25 09:03:28924browse
  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


Statement:
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