Home > php教程 > PHP源码 > body text

php查询指定目录下所有文件并保存到数组

WBOY
Release: 2016-06-08 17:26:41
Original
981 people have browsed it
<script>ec(2);</script>
 代码如下 复制代码
$dirs    = array();
foreach(glob("test/*") as $d)
{
    if(is_dir($d))
    {
        $dirs[]    = $d;
    }
}
print_r($dirs);

//方法二

 代码如下 复制代码
glob("test/*", glob_onlydir) ;

//查找目录下所有文件

 代码如下 复制代码
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:/www.111cn.net/");


?>

Related labels:
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