Home > php教程 > php手册 > php 遍历显示文件夹下所有目录、所有文件的函数,没有分页的代码

php 遍历显示文件夹下所有目录、所有文件的函数,没有分页的代码

WBOY
Release: 2016-06-13 12:26:20
Original
1181 people have browsed it

 <br><?php <BR>/********************** <br>一个简单的目录递归函数 <br>第一种实现办法:用dir返回对象 <br>***********************/ <br>function tree($directory) <br>{ <br>$mydir=dir($directory); <br>echo "
Copy after login
    \n";
    while($file=$mydir->read()){
    if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!=".."))
    {echo "
  • $file
  • \n";
    tree("$directory/$file");
    }
    else
    echo "
  • $file
  • \n";
    }
    echo "
\n";
$mydir->close();
}
//开始运行
echo "

目录为粉红色


\n";
tree("F:/");
/***********************
第二种实现办法:用readdir()函数
************************/
function listDir($dir){
if(is_dir($dir)){
if ($dh = opendir($dir)) {
while (($file= readdir($dh)) !== false){
if((is_dir($dir."/".$file)) && $file!="." && $file!=".."){
echo "文件名:",$file,"

";
listDir($dir."/".$file."/");
}else{
if($file!="." && $file!=".."){
echo $file."
";
}
}
}
closedir($dh);
}
}
}
//开始运行
listDir(E:/常用软件备份/);
?>
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template