I wrote a script to print the names of all files and folders, recursively, to console. I want to edit this to print it in an excel spreadsheet/csv like so :
Folder
FullPath/Folder/File.extension, Folder, Extension
...
...
Recursively do this for all documents in the folder.
Here is my script to do it in Console :
package test;
import java.io.File;
import java.io.IOException;
public class RecursiveFileDisplay {
public static void main(String[] args) {
File currentDir = new File("."); // current directory
displayDirectoryContents(currentDir);
}
public static void displayDirectoryContents(File dir) {
try {
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
System.out.println("directory:" + file.getCanonicalPath());
displayDirectoryContents(file);
} else {
System.out.println(" file:" + file.getCanonicalPath());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
How can I adapt this to print to an Excel spreadsheet or CSV?
Thanks.