首页 >后端开发 >php教程 >PHP遍历某个目录下的所有文件和子文件夹的实现代码_PHP教程

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

WBOY
WBOY原创
2016-07-21 15:02:02916浏览

复制代码 代码如下:

 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;
    }
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327951.htmlTechArticle复制代码 代码如下: ?php function read_all_dir ( $dir ) { $result = array(); $handle = opendir($dir); if ( $handle ) { while ( ( $file = readdir ( $handle ) ) !== false ) {...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn