Definition and usage
The glob () function returns a file name or directory that matches the specified mode.
This function returns an array containing matching files/directories. If an error occurs, false is returned.
Syntax
glob(pattern,flags)
Parameters |
Description |
File |
Required. Specify the search mode. |
Size |
Optional. Specify special settings.
- Glob_mark-Add a diagonal line to each returned item
- Glob_nosort-returns (unordered) files in the original order in the directory)
- Glob_nocheck-returns the search mode if no matching file exists.
- Glob_noescape
- Glob_brace-extended {a, B, c} to match 'A', 'B' or 'C'
- Glob_onlydir-returns only directory items that match the pattern.
- Glob_err-stop and read error messages (such as unreadable Directories). All errors are ignored by default.
Note: glob_err is added in PHP 5.1. |
<? PHP
// Glob ()
// Retrieve all "*. txt" files in the current directory
$ Files = glob ("*. txt ");
Foreach ($ files as $ filename ){
Echo "File Name: $ FILENAME". "file size:". filesize ($ filename). "/N ";
}
// Retrieve all subdirectories starting with "T" in the current directory
$ Files = glob ("T *", glob_onlydir );
Foreach ($ files as $ filename ){
Echo "File Name: $ FILENAME". "file size:". filesize ($ filename). "/N ";
}
// Retrieve all PHP files starting with "D, T, or P" in the current directory
$ Files = glob ("{d, T, P} *. php", glob_brace );
Foreach ($ files as $ filename ){
Echo "File Name: $ FILENAME". "file size:". filesize ($ filename). "/N ";
}
?>