View source code
Display the source code in std/path.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.path.globMatch
Matches a pattern
against a path
.
Some characters of pattern
have a special meaning (they are
meta-characters) and can't be escaped. These are:
*
?
[
chars]
[!
chars]
{
string1
string2
…}
Individual characters are compared using
,
where filenameCharCmp
!cscs
is an optional template parameter determining whether
the comparison is case sensitive or not. See the
filenameCharCmp
documentation for details.
Note that directory
separators and dots don't stop a meta-character from matching
further portions of the path
.
Prototype
bool globMatch(std.path.CaseSensitive cs, C, Range)( Range path, const(C)[] pattern ) pure nothrow @safe if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!C && is(Unqual!C == Unqual!(ElementEncodingType!Range)));
Parameters
Name | Description |
---|---|
cs | Whether the matching should be case-sensitive |
path | The path to be matched against |
pattern | The glob pattern |
Returns
See also
Examples
assert (globMatch("foo.bar", "*"));
assert (globMatch("foo.bar", "*.*"));
assert (globMatch(foo/foo\bar
, "f*b*r"));
assert (globMatch("foo.bar", "f???bar"));
assert (globMatch("foo.bar", "[fg]???bar"));
assert (globMatch("foo.bar", "[!gh]*bar"));
assert (globMatch("bar.fooz", "bar.{foo,bif}z"));
assert (globMatch("bar.bifz", "bar.{foo,bif}z"));
version (Windows)
{
// Same as calling globMatch!(CaseSensitive.no)(path, pattern)
assert (globMatch("foo", "Foo"));
assert (globMatch("Goo.bar", "[fg]???bar"));
}
version (linux)
{
// Same as calling globMatch!(CaseSensitive.yes)(path, pattern)
assert (!globMatch("foo", "Foo"));
assert (!globMatch("Goo.bar", "[fg]???bar"));
}
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu