code: static boolean deleteParentDirectoriesIfEmpty(FileSystem fs, Path root, Path path) throws IOException {
      boolean deleted = false;
      try {
        for (Path current = path.getParent();
             !current.equals(root) && !(current.getParent() == null);
             current = current.getParent()) {
          final FileStatus[] stats = fs.listStatus(current);
          if (stats == null || stats.length == 0) {
            // dir is empty and should be removed
            LOG.debug("Deleting empty path {}", current);
            deleted = fs.delete(current, true) || deleted;
          } else {
            // all parent directories will be non-empty
            break;
          }
        }
      } catch (FileNotFoundException e) {
        LOG.debug("Path does not exist it may have been deleted by another process.", e);
      }
      return deleted;
    }
docs: Deletes the empty parent directories of the specified path.
  The method catches and ignores FileNotFoundException as it is possible that multiple parallel Kite instances are
  importing into a directory under the same root directory and it can happen that a Kite instance founds an empty
  directory which needs to be deleted but when it tries execute the delete command the folder is missing
  because it has been already deleted by another Kite instance.
  
  @param fs   the FileSystem
  @param root The empty parent directories have to be deleted up to this root directory.
  @param path The parent directories of this path will be deleted.
  @return True if at least one empty parent directory was deleted false otherwise.
  @throws IOException