FileSystem.GetPathMatcher(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a PathMatcher
that performs match operations on the
String
representation of Path
objects by interpreting a
given pattern.
[Android.Runtime.Register("getPathMatcher", "(Ljava/lang/String;)Ljava/nio/file/PathMatcher;", "GetGetPathMatcher_Ljava_lang_String_Handler", ApiSince=26)]
public abstract Java.Nio.FileNio.IPathMatcher? GetPathMatcher (string? syntaxAndPattern);
[<Android.Runtime.Register("getPathMatcher", "(Ljava/lang/String;)Ljava/nio/file/PathMatcher;", "GetGetPathMatcher_Ljava_lang_String_Handler", ApiSince=26)>]
abstract member GetPathMatcher : string -> Java.Nio.FileNio.IPathMatcher
Parameters
- syntaxAndPattern
- String
The syntax and pattern
Returns
A path matcher that may be used to match paths against the pattern
- Attributes
Remarks
Returns a PathMatcher
that performs match operations on the String
representation of Path
objects by interpreting a given pattern.
The syntaxAndPattern
parameter identifies the syntax and the pattern and takes the form: <blockquote>
<i>syntax</i><b>:</b><i>pattern</i>
</blockquote> where ':'
stands for itself.
A FileSystem
implementation supports the "glob
" and "regex
" syntaxes, and may support others. The value of the syntax component is compared without regard to case.
When the syntax is "glob
" then the String
representation of the path is matched using a limited pattern language that resembles regular expressions but with a simpler syntax. For example:
<table class="striped" style="text-align:left; margin-left:2em"> <caption style="display:none">Pattern Language</caption> <thead> <tr> <th scope="col">Example <th scope="col">Description </tr> </thead> <tbody> <tr> <th scope="row">*.java
</th> <td>Matches a path that represents a file name ending in .java
</td> </tr> <tr> <th scope="row">*.*
</th> <td>Matches file names containing a dot</td> </tr> <tr> <th scope="row">*.{java,class
}</th> <td>Matches file names ending with .java
or .class
</td> </tr> <tr> <th scope="row">foo.?
</th> <td>Matches file names starting with foo.
and a single character extension</td> </tr> <tr> <th scope="row">/home/*/*
<td>Matches /home/gus/data
</td> </tr> <tr> <th scope="row">/home/**
<td>Matches /home/gus
and /home/gus/data
</td> </tr> </tbody> </table>
The following rules are used to interpret glob patterns:
<ul> <li>
The *
character matches zero or more Character characters
of a Path#getName(int) name
component without crossing directory boundaries.
</li>
<li>
The **
characters matches zero or more Character characters
crossing directory boundaries.
</li>
<li>
The ?
character matches exactly one character of a name component.
</li>
<li>
The backslash character (\
) is used to escape characters that would otherwise be interpreted as special characters. The expression \\
matches a single backslash and "\{" matches a left brace for example.
</li>
<li>
The [ ]
characters are a bracket expression that match a single character of a name component out of a set of characters. For example, [abc]
matches "a"
, "b"
, or "c"
. The hyphen (-
) may be used to specify a range so [a-z]
specifies a range that matches from "a"
to "z"
(inclusive). These forms can be mixed so [abce-g] matches "a"
, "b"
, "c"
, "e"
, "f"
or "g"
. If the character after the [
is a !
then it is used for negation so [!a-c]
matches any character except "a"
, "b"
, or "c"
.
Within a bracket expression the *
, ?
and \
characters match themselves. The (-
) character matches itself if it is the first character within the brackets, or the first character after the !
if negating.
</li>
<li>
The {
} characters are a group of subpatterns, where the group matches if any subpattern in the group matches. The ","
character is used to separate the subpatterns. Groups cannot be nested.
</li>
<li>
Leading period/
dot characters in file name are treated as regular characters in match operations. For example, the "*"
glob pattern matches file name ".login"
. The Files#isHidden
method may be used to test whether a file is considered hidden.
</li>
<li>
All other characters match themselves in an implementation dependent manner. This includes characters representing any FileSystem#getSeparator name-separators
.
</li>
<li>
The matching of Path#getRoot root
components is highly implementation-dependent and is not specified.
</li>
</ul>
When the syntax is "regex
" then the pattern component is a regular expression as defined by the java.util.regex.Pattern
class.
For both the glob and regex syntaxes, the matching details, such as whether the matching is case sensitive, are implementation-dependent and therefore not specified.
Java documentation for java.nio.file.FileSystem.getPathMatcher(java.lang.String)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.