zoukankan      html  css  js  c++  java
  • 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;
        }
    ?>

  • 相关阅读:
    Codeforces 526D Om Nom and Necklace (KMP)
    HDU
    HDU
    Codeforces 219D
    HDU
    HDU
    POJ
    HDU
    HDU
    第二次作业
  • 原文地址:https://www.cnblogs.com/akuo-123/p/8059085.html
Copyright © 2011-2022 走看看