Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1.     static public function GetFiles( $dirName = '.', $mask = '*.*', $relative = 0, $recurse = 1 )
  2.     {
  3.         if( !isset($dirName) || $dirName == '' )
  4.         { $dirName = '.'; }
  5.  
  6.         if( !is_dir( $dirName ) || !is_readable( $dirName ) )
  7.         { return false; }
  8.        
  9.         $files = Array( );
  10.         $handle = @opendir($dirName);
  11.        
  12.         $mask = str_replace('.', '\.', $mask);
  13.         $mask = str_replace('*', '.*', $mask);
  14.  
  15.         while( false !== ( $file = readdir( $handle ) ) )
  16.         {      
  17.             if( $file != '.' && $file != '..' )
  18.             {          
  19.                 $fullPath = $dirName . DIRECTORY_SEPARATOR . $file;
  20.                
  21.                 if(is_readable( $fullPath ))
  22.                 {
  23.                     if( is_dir( $fullPath ) )
  24.                     {
  25.                         if($recurse)
  26.                         {
  27.                             $subs = self::GetFiles( $fullPath, $mask, $relative, $recurse );
  28.  
  29.                             foreach($subs as $sub)
  30.                             { $files[] = $sub; }
  31.                         }
  32.                     }
  33.                     else
  34.                     {
  35.                         $path = ( $relative ? $file : $fullPath );
  36.                    
  37.                         preg_match('/' . $mask . '/i', $path, $result);
  38.                        
  39.                         if(count($result) > 0)
  40.                         { $files[] = $path; }
  41.                     }
  42.                 }
  43.             }
  44.         }
  45.  
  46.         @closedir($handle);    
  47.         return $files;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement