code: private static Path getDirectory(FileSystem fs, Path path) {
      try {
        if (!fs.exists(path) || fs.isDirectory(path)) {
          return path;
        } else {
          return path.getParent();
        }
  
      } catch (IOException e) {
        throw new DatasetIOException("Cannot access path: " + path, e);
      }
    }
docs: Returns the closest directory for the given {@code path}.
  
  @param fs a {@link FileSystem} to search
  @param path a {@link Path} to resolve
  @return the closest directory to {@link Path}