Home >php教程 >php手册 >PHP遍历某个目录下的所有文件和子文件夹的实现代码

PHP遍历某个目录下的所有文件和子文件夹的实现代码

WBOY
WBOYOriginal
2016-06-06 20:29:101357browse

本篇文章是对PHP遍历某个目录下的所有文件和子文件夹的实现代码进行了详细的分析介绍,需要的朋友参考下

复制代码 代码如下:


function read_all_dir ( $dir )
{
$result = array();
$handle = opendir($dir);
if ( $handle )
{
while ( ( $file = readdir ( $handle ) ) !== false )
{
if ( $file != '.' && $file != '..')
{
$cur_path = $dir . DIRECTORY_SEPARATOR . $file;
if ( is_dir ( $cur_path ) )
{
$result['dir'][$cur_path] = read_all_dir ( $cur_path );
}
else
{
$result['file'][] = $cur_path;
}
}
}
closedir($handle);
}
return $result;
}
?>

,美国服务器,网站空间,香港虚拟主机
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