Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.luxoft.datastructures;
- import java.io.File;
- public class FileManager {
- public static int countFiles(File path) {
- int counter=0;
- File[] innerPaths = path.listFiles();
- if (innerPaths!=null) {
- for (File innerPath : innerPaths) {
- if (innerPath.isDirectory()) {
- counter += countFiles(innerPath);
- } else {
- counter++;
- }
- }
- }
- return counter;
- }
- public static int countDirs(File path){
- int counter=0;
- File[] innerPaths = path.listFiles();
- if (innerPaths!=null) {
- for (File innerPath : innerPaths) {
- if (innerPath.isDirectory()) {
- counter++;
- counter += countDirs(innerPath);
- }
- }
- }
- return counter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement