Delete file, recursively if needed

@param file File/Directory to delete
769476
private synchronized static void delete(File file) {
        // Check if file is directory
        if (file.isDirectory()) {
            // Get all files in the folder
            File[] files = file.listFiles();

            // Delete each file in the folder
            for (int i = 0; i < files.length; ++i) {
                delete(files[i]);
            }

            // Delete the folder
            file.delete();
        } else {
            // Delete the file if it is not a folder
            file.delete();
        }
    }
3941
public static void delete(final File f) {
        if (f != null && f.exists()) {
            // Why do we have to specify a return type for the run method and paramatize
            // PrivilegedExceptionAction to it, this method should have a void return type ideally.
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
                @Override
                public Object run() {
                    if (!f.delete()) {
                        logger.log(Level.INFO, Messages.INSTALL_KERNEL_MESSAGES.getLogMessage("LOG_CANNOT_DELETE_FILE",
                                                                                              f.getAbsolutePath()));
                        f.deleteOnExit();
                    }

                    return null;
                }
            });
        }
    }
114335
private void delete(File file) {
		if (file.isDirectory()) {
			File[] children = file.listFiles();
			for (File child : children) {
				delete(child);
			}
		}
		if (!file.delete()) {
			if (!file.isDirectory()) {
				logger.warn("Unable to clean/delete file: {}", file);
			} else {
				logger.debug("Unable to clean/delete directory: {}", file);
			}
		}
	}
1028319
public static boolean delete(File f) {
		if (f == null || !f.exists()) return true;
		if (f.isDirectory()) {
			File[] subFiles = f.listFiles();
			if (subFiles != null) {
				for (File sf : subFiles) {
					IOUtil.delete(sf);
				}
			}
		}
		return f.delete();
	}
1370088
public synchronized void remove(final File file) {
        final T t = cache.get(file);
        expiry.remove(file);
        cache.remove(file);
        if (null != t && t instanceof Expireable) {
            final Expireable exp = (Expireable) t;
            exp.expire();
        }
    }
829206
public static void deleteFile(File file)
    {
        Check.notNull(file);

        try
        {
            Files.delete(file.toPath());
        }
        catch (final IOException exception)
        {
            throw new LionEngineException(exception, ERROR_DELETE_FILE + file.getAbsolutePath());
        }
    }
636183
private void deleteRecursive(final File file) {
        if (file.isDirectory()) {
            final String[] files = file.list();
            if (files != null) {
                for (String name : files) {
                    deleteRecursive(new File(file, name));
                }
            }
        }

        if (!file.delete()) {
            ControllerLogger.ROOT_LOGGER.cannotDeleteFileOrDirectory(file);
        }
    }
899475
public static boolean delete(File d) {
        if (null == d || !d.exists())
            return true; // by definition

        if (d.isDirectory()) {
            File[] files = d.listFiles(); // and directories
            if (null != files) {
                for (File f : files) {
                    if (f.isDirectory()) {
                        delete(f);
                    } else {
                        f.delete();
                    }
                }
            }
        }
        return d.delete();
    }
1327054
def __delete_file(self, file):
        

        for file_node in self.__script_editor.model.get_file_nodes(file, self.__script_editor.model.root_node):
            self.__script_editor.unregister_node_path(file_node)
            self.__delete_path(file)
            if self.__script_editor.model.is_authoring_node(file_node):
                self.__script_editor.get_editor(file).set_modified(True)
            else:
                self.__script_editor.model.unregister_file(file_node)
867367
private void doDelete(java.io.File file)
    {
        // Make the directory to write the objects to.
        if (file.isDirectory()) {

            // Find all of the files in the next level.

            // JCLRM does not have listFiles...
            // java.io.File nextFiles[] = file.listFiles();

            String[] files = file.list();
            java.io.File[] nextFiles = null;
            if (files != null) {
                nextFiles = new java.io.File[files.length];
                for (int iFile = 0; iFile < nextFiles.length; iFile++) {
                    nextFiles[iFile] = new java.io.File(file.getPath(),
                                                        files[iFile]);
                }
            }

            if (nextFiles != null) {
                for (int iFile = 0; // Index to next files.
                iFile < nextFiles.length; iFile++) {
                    java.io.File nextFile = nextFiles[iFile];
                    if (nextFile.isDirectory()) {
                        doDelete(nextFile);
                    } else {
                        nextFile.delete();
                    }
                } // for loop over existing Files.
            }
        } // if (file.isDirectory()).
        file.delete();
    }
798094
public static boolean delFileOrFolder(File file) {
        if (file == null || !file.exists()) {
            // do nothing
        } else if (file.isFile()) {
            file.delete();
        } else if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (files != null) {
                for (File sonFile : files) {
                    delFileOrFolder(sonFile);
                }
            }
            file.delete();
        }
        return true;
    }
415573
public static void deleteRecursive(@Nonnull File dir) throws IOException {
        deleteRecursive(fileToPath(dir), PathRemover.PathChecker.ALLOW_ALL);
    }
753516
public static void delete(String filename) {
		File file = new File(filename);
		if(file.exists()){
			file.delete();
		}
	}
555988
public static void deleteIfExists(final File file)
    {
        if (file.exists())
        {
            try
            {
                Files.delete(file.toPath());
            }
            catch (final IOException ex)
            {
                LangUtil.rethrowUnchecked(ex);
            }
        }
    }
857510
public static final void deleteQuietly(File file)
   {
      if (file != null)
      {
         if (file.isDirectory())
         {
            File[] children = file.listFiles();
            if (children != null)
            {
               for (File child : children)
               {
                  deleteQuietly(child);
               }
            }
         }
         file.delete();
      }
   }
453843
@NotNull
    public static boolean delete(@Nullable File file) {
        if (file == null) {
            LOGGER.warn("cannot delete null File");
            return false;
        }

        final boolean success = org.apache.commons.io.FileUtils.deleteQuietly(file);
        if (!success) {
            LOGGER.debug("Failed to delete file: {}; attempting to delete on exit.", file.getPath());
            file.deleteOnExit();
        }
        return success;
    }
944512
public static void deleteDirectory(File directory) throws IOException {
    if (!directory.exists()) {
      return;
    }

    if (!isSymlink(directory)) {
      cleanDirectory(directory);
    }

    if (!directory.delete()) {
      String message =
          "Unable to delete directory " + directory + ".";
      throw new IOException(message);
    }
  }