code: public static void deleteDirIfExists(UnderFileSystem ufs, String path) throws IOException {
      if (ufs.isDirectory(path)
          && !ufs.deleteDirectory(path, DeleteOptions.defaults().setRecursive(true))) {
        throw new IOException("Folder " + path + " already exists but can not be deleted.");
      }
    }
docs: Deletes the directory at the given path if it exists.
  
  @param ufs instance of {@link UnderFileSystem}
  @param path path to the directory