File_Find::glob() – find matches for a pattern in a directory


require_once 'File/Find.php';

array &File_Find::glob ( string $pattern , string $dirpath , string $pattern_type = 'php' )


Search the directory to find matches for the specified pattern.


  • $pattern - a string containing the pattern to search the directory for.

  • $dirpath - a string containing the directory path to search.

  • $pattern_type - a string containing the type of pattern matching functions to use (can either be 'php', 'perl' or 'shell').

    The format of the $pattern depends on the $pattern_type-value. For more information see search methods

Return value

array - an array contains all filenames and name of subdirectories, which matches the pattern. Or a PEAR_Error.


Possible PEAR_Error values
Error code Error message Reason Solution
NULL " Cannot open directory " The given directory could not be opend. Check typing and directory permissions. This can not be caused by a competive processing the archive with Archive_Tar


This function can be called statically.


Find all PHP files in current directory

include "File/Find.php";

$dir ".";
$items = &File_Find::glob'!.*\.php$!'$dir'perl' );

Types of methods what can be used in search functions (Previous) create a view map for a directory (Next)
Last updated: Fri, 09 Oct 2015 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.