ossiejhmoore icon

Untitled

ossiejhmoore | PRO | 02/22/19 03:38:33 AM UTC | 0 ⭐ | 361 👁️ | Never ⏰ | []
Java |

880 B

|

None

|

0 👍

/

0 👎

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