java can sort it for you later, here is what I did.
public static void printy(Path rootDirPath) {
//treesets to hold paths alphabetically
TreeSet<Path> paths = new TreeSet<>();
try {
Files.walkFileTree(rootDirPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
paths.add(dir);
return super.preVisitDirectory(rootDirPath, attrs);
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
paths.add(file);
return super.visitFile(rootDirPath, attrs);
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return super.visitFileFailed(file, exc);
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
return super.postVisitDirectory(rootDirPath, exc);
}
});
//I'm printing the contents alphabetically,.. your impl might vary
paths.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
}
Hope this helps