code: private void cleanEmptyParentDirectory(Path path) throws IOException {
          Path normPath = path.normalize();
          if(normPath.equals(Paths.get(getDirectory()).normalize()) || normPath.equals(Paths.get(System.getProperty("java.io.tmpdir")).normalize())) { //stop if we reach the output or temporary directory
              return;
          }
          try {
              Files.deleteIfExists(path); //delete the directory if empty
              cleanEmptyParentDirectory(path.getParent()); //do the same with parent directory
          }
          catch(DirectoryNotEmptyException ex) {
              //if directory non-empty ignore exception
          }
      }
docs: Removes recursively all empty parent directories up to and excluding the storage directory.
  
  @param path
  @throws IOException