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])
::- Returns a list of all files matching
pattern
indirectory
. - If directory is not specified, it defaults to the current working 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
, includingRegex
andGlob.FilenameMatch
objects["a", r".", fn"c"] # again, equivalent to 1, above
- Each element of the vector will be used to match another level in the file hierarchy
- no conversion of strings to
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
-
- Returns a list of all files matching
-
readdir(pattern::GlobMatch, [directory::AbstractString])
::- alias for
glob()
- alias for
-
glob"pattern"
::- Returns a
Glob.GlobMatch
object, which can be used withglob()
orreaddir()
. See above descriptions.
- Returns a
-
fn"pattern"ipedx
::- Returns a
Glob.FilenameMatch
object, which can be used withismatch()
oroccursin()
. 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 asbash
andtcsh
- Backslash (
\
) characters in[]
groups escape the next character
- Backslash (
- Returns a
[.
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)- Advanced extended features (beyond the POSIX spec) such as
{}
groups, have not yet been implemented