Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.Stack;
- public class Main {
- public static void main(String[] args) {
- printFiles(new File("C:\\Users\\Marek\\Downloads"));
- }
- static private void printFiles(File dir) {
- Stack<FileObj> stack = new Stack<>();
- stack.push(new FileObj("", dir));
- while(!stack.isEmpty()) {
- FileObj child = stack.pop();
- if (child.file.isDirectory()) {
- System.out.println(child.depth + "<" + child.file.getName() + ">");
- for(File f : child.file.listFiles())
- {
- stack.push(new FileObj(child.depth + "\t", f));
- }
- } else if (child.file.length() / 1024 < 500) {
- System.out.println(child.depth + child.file.getName() + " (" + child.file.length() / 1024 + "KB)");
- }
- }
- }
- private static class FileObj {
- private final String depth;
- private final File file;
- public FileObj(String depth, File file) {
- this.depth = depth;
- this.file = file;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement