View source code
Display the source code in std/path.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
Function std.path.globMatch
Matches a pattern against a path.
bool globMatch(CaseSensitive cs = CaseSensitive .osDefault, C, Range)
(
Range path,
const(C)[] pattern
) pure nothrow @safe
if (isForwardRange!Range && !isInfinite!Range && isSomeChar!(ElementEncodingType!Range) && !isConvertibleToString!Range && isSomeChar!C && is(immutable(C) == immutable(ElementEncodingType!Range)));
Some characters of pattern have a special meaning (they are meta-characters) and can't be escaped. These are:
* |
Matches 0 or more instances of any character. |
? |
Matches exactly one instance of any character. |
[ chars] |
Matches one instance of any character that appears between the brackets. |
[! chars] |
Matches one instance of any character that does not appear between the brackets after the exclamation mark. |
{ string1, string2, …} |
Matches either of the specified strings. |
Individual characters are compared using filenameCharCmp!cs
,
where cs
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.
Parameters
Name | Description |
---|---|
cs | Whether the matching should be case-sensitive |
path | The path to be matched against |
pattern | The glob pattern |
Returns
true
if pattern matches path, false
otherwise.
See also
Example
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
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.