如何使用PHP遍历指定文件夹内的所有文件?
- 内容介绍
- 文章标签
- 相关推荐
本文共计116个文字,预计阅读时间需要1分钟。
plaintext遍历文件夹@param string $dir@param boolean $all true 表示递归遍历@return array**/public static function scanfDir($dir='', $all=false, &$ret=array()) {if (false !==($handle=opendir($dir))) {while (false !==($entry=readdir($handle))) {// 省略内容...}closedir($handle);}**/return $ret;
/** * 遍历文件夹 * @param string $dir * @param boolean $all true表示递归遍历 * @return array */ public static function scanfDir($dir='', $all = false, &$ret = array()){ if ( false !== ($handle = opendir ( $dir ))) { while ( false !== ($file = readdir ( $handle )) ) { if (!in_array($file, array('.', '..', '.git', '.gitignore', '.svn', '.htaccess', '.buildpath','.project'))) { $cur_path = $dir . '/' . $file; if (is_dir ( $cur_path )) { $ret['dirs'][] =$cur_path; $all && self::scanfDir( $cur_path, $all, $ret); } else { $ret ['files'] [] = $cur_path; } } } closedir ( $handle ); } return $ret; }
本文共计116个文字,预计阅读时间需要1分钟。
plaintext遍历文件夹@param string $dir@param boolean $all true 表示递归遍历@return array**/public static function scanfDir($dir='', $all=false, &$ret=array()) {if (false !==($handle=opendir($dir))) {while (false !==($entry=readdir($handle))) {// 省略内容...}closedir($handle);}**/return $ret;
/** * 遍历文件夹 * @param string $dir * @param boolean $all true表示递归遍历 * @return array */ public static function scanfDir($dir='', $all = false, &$ret = array()){ if ( false !== ($handle = opendir ( $dir ))) { while ( false !== ($file = readdir ( $handle )) ) { if (!in_array($file, array('.', '..', '.git', '.gitignore', '.svn', '.htaccess', '.buildpath','.project'))) { $cur_path = $dir . '/' . $file; if (is_dir ( $cur_path )) { $ret['dirs'][] =$cur_path; $all && self::scanfDir( $cur_path, $all, $ret); } else { $ret ['files'] [] = $cur_path; } } } closedir ( $handle ); } return $ret; }

