First, using a DirectoryStream. This is the better way.
static List
List
Path dir = FileSystems.getDefault().getPath(filePath);
DirectoryStream
try {
stream = Files.newDirectoryStream(dir, wc);
for (Path path : stream) {
result.add(path.getFileName().toString());
}
stream.close();
} catch (IOException e) {
// glob of something that does not exist is empty
}
return result;
}
Second, using File().
PathMatcher matcher = FileSystems.getDefault()
.getPathMatcher("glob:"+wc);
List
File dircontents = new File(dirname_s);
String[] paths = dircontents.list();
for (String ps : paths) {
Path p = Paths.get(ps);
if (matcher.matches(p)) {
result.add(p.toString());
}
}
Collections.sort(result);
return result;
}
blogodex = {"idx" : ["glob", "java"]};