-1

Possible Duplicate:
Recursively list files in Java

I think File[] files = folder.listFiles() can only list the first level of files. Is there a way to list files recursively?

Community
  • 1
  • 1
Adam Lee
  • 23,314
  • 47
  • 144
  • 221

1 Answers1

2

Not a built-in one, but you can write a short recursive program to do walk the directory tree recursively.

void listAll(File dir, List<File> res) {
    for (File f : dir.listFiles()) {
        if (f.isDirectory()) {
            listAll(f, res);
        } else {
            res.add(f);
        }
    }
}
Sergey Kalinichenko
  • 697,062
  • 78
  • 1,055
  • 1,465