code: private static void getFilesAndDirs(File dir, List<File> list) {
          File[] files = dir.listFiles();
          for (File element : files) {
              list.add(element);
              if (element.isDirectory()) {
                  getFilesAndDirs(element, list);
              }
          }
      }
docs: for testing via main