0

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.

Danilo Cândido
  • 408
  • 1
  • 5
  • 18
Simon Kiely
  • 5,880
  • 28
  • 94
  • 180
  • try using using text/csv mime type, and properly format the response with coma separated items. – Jordi Flores Aug 03 '16 at 13:52
  • 1
    Possible duplicate of [Java - Writing strings to a CSV file](http://stackoverflow.com/questions/30073980/java-writing-strings-to-a-csv-file) – SkyWalker Aug 03 '16 at 14:00

0 Answers0