Home  >  Article  >  php教程  >  php递归列出所有文件和目录的代码

php递归列出所有文件和目录的代码

WBOY
WBOYOriginal
2016-06-13 12:27:16829browse

/*我的程序在国外的SREVER上,自己编的程序存放到哪,我很难记清。
所以编了一个简单的目录递归函数,查看我的程序,很方便的。
*/
function tree($directory)
{
$mydir=dir($directory);
echo "

    ";
    while($file=$mydir->read()){
    if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){
    echo "
  • $file
  • ";
    tree("$directory/$file");
    }else{
    echo "
  • $file
  • ";
    }
    }
    echo "
";
$mydir->close();
}
//start the program
echo "

目录为粉红色

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