0

Possible Duplicate:
Recursively list files in Java

Java program to list all files in a drive along with the path of that file.....is it possible? how?

Community
  • 1
  • 1
user563577
  • 41
  • 4
  • 12

3 Answers3

0

Use File.listFiles() and iterate over directories recursively.

AlexR
  • 114,158
  • 16
  • 130
  • 208
0

I'm not sure if I understood you correctly, File has a method list. If you'd like to use recurrent searching, you might be interested in this tutorial.

Sebastian Łaskawiec
  • 2,667
  • 15
  • 33
0

use this:

public class Main {
    public static void main(String[] args) {
        File[] roots = File.listRoots();

        for (File root : roots) {
            showFolderRecursively(root);
        }
    }

    private static void showFolderRecursively(File root) {

        System.out.println(root.getAbsolutePath());
        File[] files = root.listFiles();
        for (File file : files) {
            if ( file.isFile() ) {
                System.out.println(file.getAbsolutePath());
            } else {
                showFolderRecursively(file);
            }
        }
    }
}
Mihai Toader
  • 12,041
  • 1
  • 29
  • 33