code: public static boolean clearDirectory(File directory) {
      if (directory.isDirectory()) {
        for (File file : directory.listFiles()) {
          if (!deleteRecursive(file)) {
            return false;
          }
        }
      }
      return true;
    }
docs: Recursively removes all entries from a directory.
  @param directory The directory to clear.
  @return A value indicating whether the directory was successfully
  cleared.  If unsuccessful, the directory may have been partially
  cleared.