code: public static void deleteEmptyParentDirectories(FileSystem fs, Path limitPath, Path startPath)
        throws IOException {
      if (PathUtils.isAncestor(limitPath, startPath) && !PathUtils.getPathWithoutSchemeAndAuthority(limitPath)
          .equals(PathUtils.getPathWithoutSchemeAndAuthority(startPath)) && fs.listStatus(startPath).length == 0) {
        if (!fs.delete(startPath, false)) {
          log.warn("Failed to delete empty directory " + startPath);
        } else {
          log.info("Deleted empty directory " + startPath);
        }
        deleteEmptyParentDirectories(fs, limitPath, startPath.getParent());
      }
    }
docs: Deletes empty directories starting with startPath and all ancestors up to but not including limitPath.
  @param fs {@link FileSystem} where paths are located.
  @param limitPath only {@link Path}s that are strict descendants of this path will be deleted.
  @param startPath first {@link Path} to delete. Afterwards empty ancestors will be deleted.
  @throws IOException