import java.io.File;
import java.util.ArrayList;
public class DirProcess {
private static ArrayList arrFiles = new ArrayList();
public String[] Result() {
String[] result = new String[arrFiles.size()];
arrFiles.toArray(result);
return result;
}
public void visitAllDirsAndFiles(String dir){
arrFiles.clear();
visitAllDirsAndFiles(new File(dir));
}
public void visitAllDirs(String dir) {
arrFiles.clear();
visitAllDirs(new File(dir));
}
private void process(File dir) {
System.out.println(dir);
arrFiles.add(dir.toString());
}
public void visitAllDirsAndFiles(File dir) {
process(dir);
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++)
visitAllDirsAndFiles(new File(dir, children));
}
}
// Process only directories under dir
public void visitAllDirs(File dir) {
if (dir.isDirectory()) {
process(dir);
String[] children = dir.list();
for (int i = 0; i < children.length; i++)
visitAllDirs(new File(dir, children));
}
}
// Process only files under dir
public void visitAllFiles(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++)
visitAllFiles(new File(dir, children));
}
else
process(dir);
}
public static void main(String args[]) {
DirProcess dirproc = new DirProcess();
dirproc.visitAllFiles(new File("myStartFolder"));
}
}