public class ListAllDir implements FilenameFilter {
public static void main(String[] args) throws Exception {
File file=new File("d:/"); //replace your directory here
if (file.isDirectory()){
String[] files=file.list(new ListAllDir());
for (int i=0;i<files.length;i++){
System.out.println(files[i]);
}
}
}
public boolean accept(File parm1, String parm2) {
return new File(parm1+"/"+parm2).isDirectory();
// Process all files and directories under dir
public static 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[i]));
}
}
}
// Process only directories under dir
public static 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[i]));
}
}
}
// Process only files under dir
public static void visitAllFiles(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
visitAllFiles(new File(dir, children[i]));
}
} else {
process(dir);
}
}