php遍历目录下所有文件和子文件夹的代码
例子:
<?php /** * 遍历目录下所有文件及子文件夹 * edit www.jbxue.com */ 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 目录遍历与删除的函数示例
php 读取目录文件夹列表的例子