Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. package com.luxoft.datastructures;
  2.  
  3. import java.io.File;
  4.  
  5. public class FileManager {
  6. public static int countFiles(File path) {
  7. int counter=0;
  8.  
  9. File[] innerPaths = path.listFiles();
  10. if (innerPaths!=null) {
  11. for (File innerPath : innerPaths) {
  12. if (innerPath.isDirectory()) {
  13. counter += countFiles(innerPath);
  14. } else {
  15. counter++;
  16. }
  17. }
  18. }
  19.  
  20. return counter;
  21. }
  22.  
  23. public static int countDirs(File path){
  24. int counter=0;
  25.  
  26. File[] innerPaths = path.listFiles();
  27. if (innerPaths!=null) {
  28. for (File innerPath : innerPaths) {
  29. if (innerPath.isDirectory()) {
  30. counter++;
  31. counter += countDirs(innerPath);
  32. }
  33. }
  34. }
  35.  
  36. return counter;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement