I have a root folder and a bunch of files and folders within. I want to generate a list of file names that are within that root folder (and sub folders), along with the location of each file.
I need the file location because I want to display the list of file names to the user and let him open the file if needed.
I have used the following code to get the file names but I'm lost on how to get the matching file locations.
public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
}
}
}
final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);
Also, right now, I'm using an array list to store the file names. Any better way/structure to make this work would also be helpful.