code: public static void prune(File file, File root) {
      while (!file.equals(root) && file.delete()) {
        file = file.getParentFile();
      }
    }
docs: Removes a file or directory and its ancestors up to, but not including
  the specified directory, until a non-empty directory is reached.
  @param file The file or directory at which to start pruning.
  @param root The directory at which to stop pruning.