path matcher java

Solutions on MaxInterview for path matcher java by the best coders in the world

showing results for - "path matcher java"
Anton
02 Nov 2019
1Tells you if a file matches your pattern
2
3FileSystem fileSystem = FileSystems.getDefault();
4		PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:**/testFile.?");
5		Path path = Paths.get("D:/cp/testFile.t");
6		System.out.println(pathMatcher.matches(path));
7
8The "glob:" says that we are glob. You can also regex
9* It matches zero , one or more than one characters. 
10  While matching, it will not cross directories boundaries.
11** It does the same as * but it crosses the directory boundaries.
12? It matches only one character for the given name.
13\ It helps to avoid characters to be interpreted as special characters.
14[] In a set of characters, only single character is matched. 
15  If (-) hyphen is used then, it matches a range of characters. 
16  Example: [efg] matches "e","f" or "g" . [a-d] matches a range from a to d.
17{} It helps to matches the group of sub patterns.
18
19In case of "regex", pattern is regular expression defined by java.util.regex.Pattern. 
20    Read java.util.regex.Pattern to get "regex" more.
21    
22If you want to find a file that matches the pattern consider using FileVistor
23and implementing its methods to visit each file in a directory
queries leading to this page
path matcher javapath matcher java