I am using Files.walk to display a file tree but it is showing the source directory in the file tree. How can I get rid of it?
main method
public static List<String> getFileTree(String sourceDirectoryLocation) {
List<String> tree = new ArrayList<>();
Path path = Paths.get(sourceDirectoryLocation);
int sourceCount = path.getNameCount();
try (Stream<Path> pathStream = Files.walk(path, FileVisitOption.FOLLOW_LINKS)) {
pathStream.forEach(file -> {
String indentation = " ".repeat((file.getNameCount() - sourceCount) * 4);
String fileColor;
if (file.getFileName().toString().endsWith(".sk")) {
fileColor = file.getFileName().toString().startsWith("-") ? "<red>" : "<green>";
} else if (Files.isDirectory(file)) {
fileColor = "<gold>";
} else {
fileColor = "<white>";
}
tree.add(indentation + (indentation.equals("") ? "" : "<gray>└ ") + fileColor + file.getFileName());
});
} catch (IOException e) {
throw new RuntimeException("Error while getting a file tree.", e);
}
return tree;
}
how i'm using it
case "list" -> FileUtils.getFileTree("./plugins/Skript/scripts/")
.forEach(message -> send(sender, message));
as you can see in the image, it displays "scripts" which is the source directory