package deleteme;
import java.io.File;
import java.util.Stack;
public class FindFiles {
public static void main(String[] args) {
File root = new File(".");
Stack<String> stack = new Stack<>();
stack.push(root.getAbsolutePath());
while (!stack.isEmpty()) {
File next = new File(stack.pop());
boolean isFile = next.isFile();
System.out.printf("[type: %s] [path: %s]%n", (isFile ? "file" : "dir"), next.getAbsolutePath());
if (!isFile) {
String [] childnames = next.list();
if (childnames != null) {
for (String childname : childnames) {
File fChild = new File(next, childname);
stack.push(fChild.getAbsolutePath());
}
}
}
}
}
}
Comments