0

Hello I have the following directory structure:

/root
   file1.js
   /folder1
      file2.js

I'm using the following code:

Path dir = Paths.get("root");
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir,"**.js")) {
    for (Path file: stream) {
        System.out.println(file.getFileName());
    }
} catch (IOException | DirectoryIteratorException x) {
    System.err.println(x);
}

I want to return all .js files in root and folder1.

If I use *.js returns file1.js , but if I use **.js returns the same file1.js.

Why is not returning the folder1/file2.js ?

According to official documentation: https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob

Two asterisks, **, works like * but crosses directory boundaries. This syntax is generally used for matching complete paths

Thanks

Doua Beri
  • 10,612
  • 18
  • 89
  • 138

0 Answers0