I have links for different directories. Like given below:
- E:\ASUG test files\new20
- E:\files\new6
- G:\test files\new1
- G:\ASUG\SubProjectFolder\new3
Each of the directories contains different no of files. I have created a TreeView for those directories but only with the directory names rather than their complete path.
Now i want to get the paths of these directories or the files in those directories whenever they are clicked... How is this possible without displaying complete paths on tree items? following is the code i have written.
String[] allPaths = AllStaticMethods.readTextFile("text files\\recentProjects.txt").split("\n");// contains paths to all directories
File[] files = new File[allPaths.length];
for (int i = 0; i < files.length; i++) {
files[i] = new File(allPaths[i]);
}
TreeItem parentTree = new TreeItem("root");
parentTree.setExpanded(true);
treeView = new TreeView<>(parentTree);
for (int i = 0; i < files.length; i++) {
TreeItem treeItem = new TreeItem(files[i].getName());
parentTree.getChildren().add(treeItem);
File[] listFiles1 = files[i].listFiles();
for (int j = 0; j < listFiles1.length; j++) {
if (!listFiles1[j].isDirectory()) {
String extension = listFiles1[j].getName();
extension = extension.replace(".", "#");
extension = extension.split("#")[1];
if (extension.equalsIgnoreCase("txt")) {
TreeItem treeItem1 = new TreeItem(listFiles1[j].getName());
treeItem.getChildren().add(treeItem1);
}
}
}
}
