Given: Directory on disk (for example: "D: / new")

File file = new File("D:/new"); File[] a = file.listFiles(); for (int i = 0; i < a.length; i++) { System.out.println(a[i]); }: 

How to check the number of files inside this directory with all subfolders

1 answer 1

Use the recursive traversal method:

  • get a list of catalog items
  • if the item is a directory, get a list of its items, etc.