Advertisement
LoganBlackisle

opg 4

Aug 27th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import java.io.File;
  2.  
  3. public class ReadFolder {
  4. static int counter = 0;
  5.  
  6. public static void scanDir(String path) {
  7. System.out.println(" " + path);
  8.  
  9. File file = new File(path);
  10. String[] names = file.list();
  11.  
  12. for (String name : names) {
  13. counter++;
  14. String newPath = path + "/" + name;
  15. if ((new File(newPath)).isDirectory()) {
  16. scanDir(newPath);
  17. }
  18. }
  19. }
  20.  
  21. public static void main(String[] args) {
  22. try {
  23. ReadFolder.scanDir("C:\\Users\\Allan Birch\\Documents");
  24. } catch (NullPointerException e) {
  25. e.getMessage();
  26. }
  27. System.out.println();
  28. System.out.println("There are " + counter + " subfolders");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement