Deletes the given directory and contents recursively using a filter.
@param dir a directory to delete
@param pathChecker a security check to validate a path before deleting
@throws IOException if the operation fails
556381
@Restricted(NoExternalUse.class)
    public static void deleteRecursive(@Nonnull Path dir, @Nonnull PathRemover.PathChecker pathChecker) throws IOException {
        newPathRemover(pathChecker).forceRemoveRecursive(dir);
    }
339504
public static void deleteFiles(File dir, FilenameFilter filter) {
        // validations
        if(dir == null) {
            throw new DataUtilException("The delete directory parameter can not be a null value");
        } else if(!dir.exists() || !dir.isDirectory()) {
            throw new DataUtilException("The delete directory does not exist: " + dir.getAbsolutePath());
        }

        // delete files
        File [] files;
        if(filter == null) {
            files = dir.listFiles();
        } else {
            files = dir.listFiles(filter);
        }
        if (files != null) {
            for(File file : files) {
                if(file.isFile()) {
                    if(!file.delete()) {
                        throw new DataUtilException("Failed to delete file: " + file.getAbsolutePath());
                    }
                }
            }
        }
    }
1080941
private static synchronized int deleteRecursively(File directory) {
		int deleted = 0;
		if(directory.isDirectory()) {
			File[] contents = directory.listFiles();
			for(File file : contents) {
				deleted += deleteRecursively(file);
			}
		} else {
			deleted++;
		}
		directory.delete();
		return deleted;
	}
513724
public boolean delete(Path f, boolean recursive) throws IOException{
    FileStatus fstatus = null;
    try {
      fstatus = fs.getFileStatus(f);
    } catch(FileNotFoundException e) {
      return false;
    }
    if(fstatus.isDir()) {
      //this works since the crcs are in the same
      //directories and the files. so we just delete
      //everything in the underlying filesystem
      return fs.delete(f, recursive);
    } else {
      Path checkFile = getChecksumFile(f);
      if (fs.exists(checkFile)) {
        fs.delete(checkFile, true);
      }
      return fs.delete(f, true);
    }
  }
11272
protected boolean deleteDirectory(Path path, boolean cleanParent) throws IOException {
        boolean pathExists = deleteIfExistsRecursively(path);
        if(pathExists && cleanParent) {
            cleanEmptyParentDirectory(path.getParent());
            return true;
        }
        return false;
    }
1340585
private boolean delete(FTPClient client, Path file, boolean recursive)
      throws IOException {
    Path workDir = new Path(client.printWorkingDirectory());
    Path absolute = makeAbsolute(workDir, file);
    String pathName = absolute.toUri().getPath();
    FileStatus fileStat = getFileStatus(client, absolute);
    if (!fileStat.isDir()) {
      return client.deleteFile(pathName);
    }
    FileStatus[] dirEntries = listStatus(client, absolute);
    if (dirEntries != null && dirEntries.length > 0 && !(recursive)) {
      throw new IOException("Directory: " + file + " is not empty.");
    }
    if (dirEntries != null) {
      for (int i = 0; i < dirEntries.length; i++) {
        delete(client, new Path(absolute, dirEntries[i].getPath()), recursive);
      }
    }
    return client.removeDirectory(pathName);
  }
814308
public final void dirRemove(File dir) throws IOException {
		if (dir != null) {
			getLog().debug("Deleting tree: " + dir.toString()); //$NON-NLS-1$
			final LinkedList<File> candidates = new LinkedList<>();
			candidates.add(dir);
			File[] children;
			final BuildContext buildContext = getBuildContext();
			while (!candidates.isEmpty()) {
				final File f = candidates.getFirst();
				getLog().debug("Scanning: " + f); //$NON-NLS-1$
				if (f.isDirectory()) {
					children = f.listFiles();
					if (children != null && children.length > 0) {
						// Non empty directory
						for (final File c : children) {
							getLog().debug("Discovering: " + c); //$NON-NLS-1$
							candidates.push(c);
						}
					} else {
						// empty directory
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						candidates.removeFirst();
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				} else {
					// not a directory
					candidates.removeFirst();
					if (f.exists()) {
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				}
			}
			getLog().debug("Deletion done"); //$NON-NLS-1$
		}
	}
1221189
public static void directoryCheck(String dir) throws IOException {
		final File file = new File(dir);

		if (!file.exists()) {
			FileUtils.forceMkdir(file);
		}
	}
275533
public static boolean deleteDir(File dir) {        
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (String file : children) {
                boolean success = deleteDir(new File(dir, file));
                if (!success) {
                    return false;
                }
            }
        }

        // The directory is now empty so delete it
        return dir.delete();
    }
409540
protected void removeFile(String subdir, String filename) throws IOException {
        Path dir = root;
        if (subdir != null) {
            dir = dir.resolve(subdir);
        }
        Files.deleteIfExists(dir.resolve(filename));
    }
368351
protected static void deleteDir(final File dir) {
    try {
      boolean _exists = dir.exists();
      boolean _not = (!_exists);
      if (_not) {
        return;
      }
      org.eclipse.xtext.util.Files.sweepFolder(dir);
      try {
        dir.delete();
      } finally {
      }
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
698862
public static void deleteFilesByRegex(File dir, String regex) {
        if(regex == null) {
            throw new DataUtilException("Filename regex can not be null");
        }
        FilenameFilter filter = new RegexFilenameFilter(regex);
        FileDeleter.deleteFiles(dir, filter);
    }
264769
public static void purgeDirectory(File directory) {

        if (directory.canRead() && directory.isDirectory()) {
            File[] files = directory.listFiles();
            for (int i = 0; i < files.length; i++) {
                File f = files[i];
                if (f.isDirectory()) {
                    purgeDirectory(f);
                }
                if (f.canWrite()) {
                    f.delete();
                }
            }
            directory.delete();
        }
    }
1159900
public static void deleteDirectories(FileSystem fs, List<String> directoriesToDelete, boolean recursive, boolean moveToTrash) throws IOException {
    for (String directory : directoriesToDelete) {
      if (moveToTrash) {
        moveToTrash(fs, new Path(directory));
      } else {
        deletePath(fs, new Path(directory), recursive);
      }
    }
  }
663798
public static void recursivelyDeleteDirectoryOnExit(final File directory) {
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        try {
          recursivelyDeleteDirectory(directory);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    });
  }
1256915
def _delete_dir(dir):
    
    try:
        shutil.rmtree(dir)  # delete directory
    except OSError as exc:
        if exc.errno != 2:  # code 2 - no such file or directory
            raise  # re-raise exception
    except UnboundLocalError:
        pass
1301146
protected static void deleteDir(File dir) {

        String files[] = dir.list();
        if (files == null) {
            files = new String[0];
        }
        for (int i = 0; i < files.length; i++) {
            File file = new File(dir, files[i]);
            if (file.isDirectory()) {
                deleteDir(file);
            } else {
            	try {
            		file.delete();
            	} catch (SecurityException se) {
            		log.error("The file " + file.getAbsolutePath() + " couldn't be deleted");
            	}
            }
        }
        try {
        	dir.delete();
        } catch (SecurityException se) {
    		log.error("The directory " + dir.getAbsolutePath() + " couldn't be deleted");
    	}
    }