When using the method
java.nio.file.Files.walkFileTree(Path root, Set options, int maxDepth, FileVisitor visitor)
one can specify the maximum depth of files to visit. Is there also a way to specify that only paths of a specific, exact depth shall be visited?
More specifically, I only want to visit directories, but this could be easily checked with
if (attrs.isDirectory()) {
// do something
}
in the visitFile
callback.
Example: Assume I have a directory structure with the files root/dir1/dir11/file.a
and root/dir2/file.b
and I call walkFileTree
on root
with maxDepth=2
. Then, I only want to process
root/dir1/dir11
I neither want to process the file root/dir2/file.b
, which has also a depth of two, nor the other directory paths with a depth less than two:
root
root/dir1
root/dir2