Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- public class ReadFolder {
- static int counter = 0;
- public static void scanDir(String path) {
- System.out.println(" " + path);
- File file = new File(path);
- String[] names = file.list();
- for (String name : names) {
- counter++;
- String newPath = path + "/" + name;
- if ((new File(newPath)).isDirectory()) {
- scanDir(newPath);
- }
- }
- }
- public static void main(String[] args) {
- try {
- ReadFolder.scanDir("C:\\Users\\Allan Birch\\Documents");
- } catch (NullPointerException e) {
- e.getMessage();
- }
- System.out.println();
- System.out.println("There are " + counter + " subfolders");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement