code: public static List<FileStatus> listStatusHelper(FileSystem fs, Path path,
        int depth, List<FileStatus> acc) throws IOException {
      FileStatus[] fileStatusResults = fs.listStatus(path);
      if (fileStatusResults == null) {
        throw new IOException("Path does not exist: " + path);
      }
  
      for (FileStatus f : fileStatusResults) {
        Path subPath = f.getPath();
        if (!f.isDir()) {
          acc.add(f); // Accumulate all files
        } else {
          if (depth > 1) {
            listStatusHelper(fs, subPath, depth - 1, acc);
          } else {
            acc.add(f); // Accumulate all leaves
          }
        }
      }
  
      return acc;
    }
docs: Core logic for listStatus