Does the actual work. Note we (a) first sort the files lexicographically
and then (b) delete them in reverse order. This is to make sure files
get deleted before their parent directories.
336879
@Override
    public void run() {
        Collections.sort(files);
        for (int i = files.size() - 1; i >= 0; i--) {
            new File(files.get(i)).delete();
        }
    }
1076953
private void deleteFiles(Predicate<File> predicate) {
    directory.mkdirs();

    // Iterate through all files in the storage directory.
    for (File file : directory.listFiles(f -> f.isFile() && predicate.test(f))) {
      try {
        Files.delete(file.toPath());
      } catch (IOException e) {
        // Ignore the exception.
      }
    }
  }
345672
public static void deleteFileOrDirectory(File file) throws IOException {
        if (file.exists()) {
            if (file.isDirectory()) {
                Path rootPath = Paths.get(file.getAbsolutePath());

                Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS)
                        .sorted(Comparator.reverseOrder())
                        .map(Path::toFile)
                        .forEach(File::delete);
            } else {
                file.delete();
            }
        } else {
            throw new RuntimeException("File or directory does not exist");
        }
    }
642183
public static boolean deleteRecursive(File file) {
		
		if(!file.exists()) {
			return false;
		}
		
		if(file.isDirectory()) {
			for(File child: file.listFiles()) {
				deleteRecursive(child);
			}
		}
		return file.delete();
	}
586103
public boolean clear() {
		boolean result = false;
		for(File file: base.listFiles()) {
			result = result | FileUtils.deleteRecursive(file);
		}
		
		return result;
	}
2993
public void cleanup() {
        if (this.childStorages != null) {
            for (FileTempStorage storage : this.childStorages) {
                storage.cleanup();
            }
        }

        for (File file : this.files.values()) {
            FileUtils.deleteQuietly(file);
        }
        this.files.clear();
    }
489436
public static void deleteFilesRecursively( File... files ) throws IOException {

		if( files == null )
			return;

		List<File> filesToDelete = new ArrayList<> ();
		filesToDelete.addAll( Arrays.asList( files ));
		while( ! filesToDelete.isEmpty()) {
			File currentFile = filesToDelete.remove( 0 );
			if( currentFile == null
					|| ! currentFile.exists())
				continue;

			// Non-empty directory: add sub-files and reinsert the current directory after
			File[] subFiles = currentFile.listFiles();
			if( subFiles != null && subFiles.length > 0 ) {
				filesToDelete.add( 0, currentFile );
				filesToDelete.addAll( 0, Arrays.asList( subFiles ));
			}

			// Existing file or empty directory => delete it
			else if( ! currentFile.delete())
				throw new IOException( currentFile.getAbsolutePath() + " could not be deleted." );
		}
	}
760810
def delete_files!(dir)
      File.delete(to_path) while setup_path(dir) && File.exist?(to_path)
    end
1155854
def _remove_files(self, predicate):
        
        found = False
        for i in range(len(self.files) - 1, -1, -1):
            if predicate(self.files[i]):
                self.debug_print(" removing " + self.files[i])
                del self.files[i]
                found = True
        return found
173970
public static boolean deleteDir(File dir) {
		if (dir != null && dir.isDirectory()) {
			String[] children = dir.list();
			for (int i = 0; i < children.length; i++) {
				if (!deleteDir(new File(dir, children[i])))
					return false;
			}
		}
		return dir.delete();
	}
531339
public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            File[] children = dir.listFiles();
            for (File child : children) {
                boolean success = deleteDir(child);
                if (!success) {
                    return false;
                }
            }
        }
        return dir.delete();
    }
192683
private void cleanUpWorkingDirectory() {
    try {
      if (this.fs.exists(this.mrJobDir)) {
        this.fs.delete(this.mrJobDir, true);
        LOG.info("Deleted working directory " + this.mrJobDir);
      }
    } catch (IOException ioe) {
      LOG.error("Failed to delete working directory " + this.mrJobDir);
    }
  }
1048298
public static boolean clearDirectory(File directory) {
		Assert.isTrue(directory.isDirectory(), "Parameter ist kein Verzeichnis");
		File[] files = directory.listFiles();
		boolean allDeleted = true;
		for (File file : files) {
			if (file.isDirectory()) {
				clearDirectory(file);
			}
			allDeleted &= file.delete();
		}

		return allDeleted;
	}
1210981
private void deleteExecutorDirs(String[] dirs) {
    for (String localDir : dirs) {
      try {
        JavaUtils.deleteRecursively(new File(localDir));
        logger.debug("Successfully cleaned up directory: {}", localDir);
      } catch (Exception e) {
        logger.error("Failed to delete directory: " + localDir, e);
      }
    }
  }
11272
protected boolean deleteDirectory(Path path, boolean cleanParent) throws IOException {
        boolean pathExists = deleteIfExistsRecursively(path);
        if(pathExists && cleanParent) {
            cleanEmptyParentDirectory(path.getParent());
            return true;
        }
        return false;
    }
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);
      }
    }
  }
1118339
private void cleanDir(File dir) {
        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                // if file is a directory, first delete all the files inside, then delete the directory itself.
                if (file.isDirectory()) {
                    cleanDir(file);
                }
                if (!file.delete()) {
                    throw new BuildException(MessageFormat.format(messages.getString("error.cannot.delete.file"), file.getAbsolutePath()));
                }
            }
        }
    }