Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Stack;
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args) {
  7. printFiles(new File("C:\\Users\\Marek\\Downloads"));
  8. }
  9.  
  10. static private void printFiles(File dir) {
  11. Stack<FileObj> stack = new Stack<>();
  12. stack.push(new FileObj("", dir));
  13. while(!stack.isEmpty()) {
  14. FileObj child = stack.pop();
  15. if (child.file.isDirectory()) {
  16. System.out.println(child.depth + "<" + child.file.getName() + ">");
  17. for(File f : child.file.listFiles())
  18. {
  19. stack.push(new FileObj(child.depth + "\t", f));
  20. }
  21. } else if (child.file.length() / 1024 < 500) {
  22. System.out.println(child.depth + child.file.getName() + " (" + child.file.length() / 1024 + "KB)");
  23. }
  24. }
  25. }
  26.  
  27. private static class FileObj {
  28. private final String depth;
  29. private final File file;
  30.  
  31. public FileObj(String depth, File file) {
  32. this.depth = depth;
  33. this.file = file;
  34. }
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement