Home  >  Article  >  php教程  >  php查询指定目录下所有文件并保存到数组

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

WBOY
WBOYOriginal
2016-06-08 17:26:41980browse
<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/");


?>

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