PHP递归遍历指定目录的文件并统计文件数量的方法
2017-02-20 13:17
826 查看
本文实例讲述了PHP递归遍历指定目录的文件并统计文件数量的方法。分享给大家供大家参考。具体实现方法如下:
希望本文所述对大家的php程序设计有所帮助。
<?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;
}
?>
PHP遍历某个目录下的所有文件和子文件夹的实现代码
代码如下:<?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;
}
?>
相关文章推荐
- PHP递归遍历指定目录的文件并统计文件数量的方法
- PHP递归遍历指定文件夹内的文件实现方法
- php遍历替换目录下文件指定内容的方法
- php递归函数实现遍历指定文件下的目录与文件数量
- PHP递归遍历指定文件夹内的文件实现方法
- PHP遍历指定目录下的文件以及文件夹
- PHP不用递归遍历目录下所有文件的代码
- 递归 / 迭代两种方法实现查找指定目录下所有文件
- [PHP]PHP自定义遍历目录下所有文件的方法
- [Linux C]递归遍历指定目录下的子目录和文件
- PHP 使用递归方法删除目录及目录下文件
- python指定文件目录遍历方法
- PHP不用递归遍历目录下所有文件的代码
- PHP: 遍历目录下特定文件的若干方法
- PHP 遍历目录下的所有文件的方法
- 递归统计指定目录下所有文件容量总和
- 遍历指定目录下指定类型文件的方法集锦
- 遍历指定目录下的所有目录和文件的php代码
- php读取指定目录文件夹下所有文件夹及文件的方法
- PHP 遍历指定文件目录