static function collect_files( $dpath, $r = false, $match = null, $ignore = null ){
		$paths = array();
		$dhandle = opendir( $dpath );
		while( $f = readdir($dhandle) ){
			if( $f === '.' || $f === '..' ){
				continue;
			}
			// pattern tested only on file name
			// ignore pattern applies to directories as well as files
			if( isset($ignore) && preg_match($ignore, $f) ){
				continue;
			}
			$path = $dpath.'/'.$f;
			if( is_dir($path) ){
				if( $r ){
					$paths = array_merge( $paths, self::collect_files($path, true, $match, $ignore) );
				}
			}
			// test match requirement on files only
			else if( isset($match) && ! preg_match($match, $f) ){
				continue;
			} 
			// else file ok to collect
			else {
				$paths[] = $path;
			}
		}
		closedir($dhandle);
		return $paths;
	}
static function collect_files( $dpath, $r = false, $match = null, $ignore = null ){
		$paths = array();
		$dhandle = opendir( $dpath );
		while( $f = readdir($dhandle) ){
			if( $f === '.' || $f === '..' ){
				continue;
			}
			// pattern tested only on file name
			// ignore pattern applies to directories as well as files
			if( isset($ignore) && preg_match($ignore, $f) ){
				continue;
			}
			$path = $dpath.'/'.$f;
			if( is_dir($path) ){
				if( $r ){
					$paths = array_merge( $paths, self::collect_files($path, true, $match, $ignore) );
				}
			}
			// test match requirement on files only
			else if( isset($match) && ! preg_match($match, $f) ){
				continue;
			} 
			// else file ok to collect
			else {
				$paths[] = $path;
			}
		}
		closedir($dhandle);
		return $paths;
	}
static function collect_files ( $ dpath , $ r = false , $ match = null , $ ignore = null ) { $ paths = array ( ) ; $ dhandle = opendir ( $ dpath ) ; while ( $ f = readdir ( $ dhandle ) ) { if ( $ f === '.' || $ f === '..' ) { continue ; } // pattern tested only on file name // ignore pattern applies to directories as well as files if ( isset ( $ ignore ) && preg_match ( $ ignore , $ f ) ) { continue ; } $ path = $ dpath . '/' . $ f ; if ( is_dir ( $ path ) ) { if ( $ r ) { $ paths = array_merge ( $ paths , self :: collect_files ( $ path , true , $ match , $ ignore ) ) ; } } // test match requirement on files only else if ( isset ( $ match ) && ! preg_match ( $ match , $ f ) ) { continue ; } // else file ok to collect else { $ paths [ ] = $ path ; } } closedir ( $ dhandle ) ; return $ paths ; }
Collect files from a directory
@param string directory path
@param bool whether to recurse into directories
@param string optional match pattern
@param string optional ignore pattern (match overrides)
@return array absolute paths collected
Collect files from a directory