I've got this problem.
When as a pattern, I enter "**/*.*" it results in listing every file in every subdir (as expected) but when entering "*.*" it prints zero results.
This is (not) my code, I copied it from some site and only added List<Path> part
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
public class FileGlobNIO {
public static List<Path> paths = new ArrayList<Path>();
public static void match(String glob, String location) throws IOException {
final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(
glob);
Files.walkFileTree(Paths.get(location), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path,
BasicFileAttributes attrs) throws IOException {
if (pathMatcher.matches(path)) {
paths.add(path);
System.out.println(path); // debug
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc)
throws IOException {
return FileVisitResult.CONTINUE;
}
});
}
}
And this is main.java
import java.io.IOException;
public class Main {
public static void main (String[] args) {
String glob = "glob:**/*.*";
String path = "C:/Users/Krzysiek/Desktop/";
try {
FileGlobNIO.match(glob, path);
System.out.println(FileGlobNIO.paths.size());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Also where could I add return paths in the first file? Or is accessing it from the other file as FileGlobNIO.paths better?