Home > 类库下载 > PHP类库 > body text

PHP source code traverses all files in a directory

高洛峰
Release: 2016-10-29 11:07:05
Original
1706 people have browsed it

php source code to traverse all the files in the directory:

<!--?php
//遍历目录下的所有的文件 -- 递归调用
// <a rel="nofollow" href=" 
 target="_blank"-->http://www.manongjc.com/article/1495.html
function get_all_file1($path){
    if($path != &#39;.&#39; && $path != &#39;..&#39; && is_dir($path)){     
    //判断是否是目录,并且不是. 和..
        $files = [];                                        
        //存储文件信息
        if($handle = opendir($path)){                       
        //打开
            while($file = readdir($handle)){                
            //读取
                if($file != &#39;.&#39; && $file != &#39;..&#39;){
                    $file_name = ($path . DIRECTORY_SEPARATOR . $file);
                    if(is_dir($file_name)){                 
                    //判断是否是目录
                        $files[$file] = get_all_file1($file_name);      
                        //递归
                    }else{
                        $files[] = $file_name;
                    }
                }
            }
        }
    }
    closedir($handle);                                          
    //关闭句柄
    return $files;
}
// <a rel="nofollow" href="http://www.manongjc.com/article/1481.html" 
target="_blank">http://www.manongjc.com/article/1481.html</a>
var_dump(get_all_file1(&#39;F:\Apache\www\temp\php_demo&#39;));
?>
Copy after login

The above is the content of the php source code to traverse all the files in the directory. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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