This implementation of Glob is based on the IEEE Std 1003.1, 2004 Edition (Open Group Base Specifications Issue 6) for fnmatch and glob. The specification of which can be found online: fnmatch and glob.
Note, because this is based on the POSIX specification, the path separator in a glob pattern is always
/
and the escape character is always\
. However, the returned path string will always contain the system path separator characterBase.path_separator
. Therefore, it may be true that a path returned byglob
will fail to match aGlob.FilenameMatch
constructed from the same pattern.
Glob is implemented to have both a functional form and an object-oriented form. There is no "correct" choice; you are encouraged to pick whichever is better suited to your application.
glob(pattern, [directory::AbstractString])
::
pattern
in directory
.Pattern can be any of:
A Glob.GlobMatch
object:
glob"a/?/c"
A string, which will be converted into a GlobMatch expression:
"a/?/c" # equivalent to 1, above
A vector of strings and/or objects which implement occursin
, including Regex
and Glob.FilenameMatch
objects
["a", r".", fn"c"] # again, equivalent to 1, above
Glob.FilenameMatch
objects or directory splitting on /
will occur.A trailing /
(or equivalently, a trailing empty string in the vector) will cause glob to only match directories
Attempting to creat a GlobMatch object from a string with a leading /
or the empty string is an error
readdir(pattern::GlobMatch, [directory::AbstractString])
::
glob()
glob"pattern"
::
Glob.GlobMatch
object, which can be used with glob()
or readdir()
. See above descriptions.fn"pattern"ipedx
::
Glob.FilenameMatch
object, which can be used with ismatch()
or occursin()
. Available flags are:i
= CASELESS
: Performs case-insensitive matchingp
= PERIOD
: A leading period (.
) character must be exactly matched by a period (.
) character (not a ?
, *
, or []
). A leading period is a period at the beginning of a string, or a period after a slash if PATHNAME is true.e
= NOESCAPE
: Do not treat backslash (\
) as a special character (in extended mode, this only outside of []
)d
= PATHNAME
: A slash (/
) character must be exactly matched by a slash (/
) character (not a ?
, *
, or []
)x
= EXTENDED
: Additional features borrowed from newer shells, such as bash
and tcsh
\
) characters in []
groups escape the next character[.
collating symbols only accept single characters (the Unicode locale has no collating symbols defined)[=
equivalence classes only match the exact character specified (the Unicode locale has no equivalence classes defined){}
groups, have not yet been implemented