ossiejhmoore

Untitled

Feb 21st, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package deleteme;
  2.  
  3. import java.io.File;
  4. import java.util.Stack;
  5.  
  6. public class FindFiles {
  7.  
  8.     public static void main(String[] args) {
  9.         File root = new File(".");
  10.         Stack<String> stack = new Stack<>();
  11.         stack.push(root.getAbsolutePath());
  12.         while (!stack.isEmpty()) {
  13.             File next = new File(stack.pop());
  14.             boolean isFile = next.isFile();
  15.             System.out.printf("[type: %s] [path: %s]%n", (isFile ? "file" : "dir"), next.getAbsolutePath());
  16.             if (!isFile) {
  17.                 String [] childnames = next.list();
  18.                 if (childnames != null) {
  19.                     for (String childname : childnames) {
  20.                         File fChild = new File(next, childname);
  21.                         stack.push(fChild.getAbsolutePath());
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment