Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public function GetFiles( $dirName = '.', $mask = '*.*', $relative = 0, $recurse = 1 )
- {
- if( !isset($dirName) || $dirName == '' )
- { $dirName = '.'; }
- if( !is_dir( $dirName ) || !is_readable( $dirName ) )
- { return false; }
- $files = Array( );
- $handle = @opendir($dirName);
- $mask = str_replace('.', '\.', $mask);
- $mask = str_replace('*', '.*', $mask);
- while( false !== ( $file = readdir( $handle ) ) )
- {
- if( $file != '.' && $file != '..' )
- {
- $fullPath = $dirName . DIRECTORY_SEPARATOR . $file;
- if(is_readable( $fullPath ))
- {
- if( is_dir( $fullPath ) )
- {
- if($recurse)
- {
- $subs = self::GetFiles( $fullPath, $mask, $relative, $recurse );
- foreach($subs as $sub)
- { $files[] = $sub; }
- }
- }
- else
- {
- $path = ( $relative ? $file : $fullPath );
- preg_match('/' . $mask . '/i', $path, $result);
- if(count($result) > 0)
- { $files[] = $path; }
- }
- }
- }
- }
- @closedir($handle);
- return $files;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement