File_Find::glob PHP Метод

glob() публичный Метод

Search specified directory to find matches for specified pattern
Автор: Sterling Hughes ([email protected])
public glob ( string $pattern, string $dirpath, string $pattern_type = 'php' ) : array
$pattern string a string containing the pattern to search the directory for.
$dirpath string a string containing the directory path to search.
$pattern_type string a string containing the type of pattern matching functions to use (can either be 'php', 'perl' or 'shell').
Результат array containing all of the files and directories matching the pattern or null if no matches
    function &glob($pattern, $dirpath, $pattern_type = 'php')
    {
        $dh = @opendir($dirpath);
        if (!$dh) {
            $pe = PEAR::raiseError("Cannot open directory {$dirpath}");
            return $pe;
        }
        $match_function = File_Find::_determineRegex($pattern, $pattern_type);
        $matches = array();
        // empty string cannot be specified for 'php' and 'perl' pattern
        if ($pattern || $pattern_type != 'php' && $pattern_type != 'perl') {
            while (false !== ($entry = @readdir($dh))) {
                if ($match_function($pattern, $entry) && $entry != '.' && $entry != '..') {
                    $matches[] = $entry;
                }
            }
        }
        @closedir($dh);
        if (0 == count($matches)) {
            $matches = null;
        }
        sort($matches);
        return $matches;
    }

Usage Example

Пример #1
0
 function readdir($dir)
 {
     if (isset(self::$cache[$dir])) {
         return self::$cache[$dir];
     }
     return self::$cache[$dir] = File_Find::glob(".*", $dir, self::EXT);
 }
All Usage Examples Of File_Find::glob