Java Utililty Methods Delete Directory

List of utility methods to do Delete Directory

Description

The list of methods to do Delete Directory are organized into topic(s).

Method

voiddeleteFiles(File[] intermediateFiles)
delete Files
for (int i = 0; i < intermediateFiles.length; i++) {
    if (!intermediateFiles[i].delete()) {
        throw new IOException("Problem while deleting intermediate file");
voiddeleteFiles(FileFilter filter)
delete Files
File[] files = workingDir.listFiles(filter);
for (File f : files) {
    f.delete();
voiddeleteFiles(final ArrayList files)
delete Files
if (files == null)
    return;
for (int i = 0; i < files.size(); i++) {
    File file = files.get(i);
    if (file == null)
        continue;
    deleteFile(file);
File[]deleteFiles(final File directory, final String regexPattern)
delete Files
final Pattern pattern = Pattern.compile(regexPattern);
final Collection<File> deletedFiles = new ArrayList<>();
final File[] files = directory.listFiles();
if (files == null) {
    throw new IllegalArgumentException(directory + " is not a directory");
for (final File file : files) {
    if (pattern.matcher(file.getName()).find()) {
...
booleandeleteFiles(final File file)
Utility function for deleting the files in a given directory and the directory itself.
boolean ok = true;
if (file != null) {
    if (file.isDirectory()) {
        final File[] files = file.listFiles();
        if (files != null) {
            for (final File f : files) {
                if (f.isFile()) {
                    ok &= f.delete();
...
voiddeleteFiles(final File... files)
Delete a list of files, and write a warning message if one could not be deleted.
for (final File f : files) {
    if (!f.delete()) {
        System.err.println("Could not delete file " + f);
ListdeleteFiles(List files)
This deletes the files in the given list.
List<File> notDeleted = new ArrayList<File>();
for (File f : files) {
    if (!f.delete()) {
        notDeleted.add(f);
return notDeleted;
booleandeleteFiles(String dir)
delete Files
boolean success = false;
File dirs = new File(dir);
if (dirs.exists() && dirs.isDirectory()) {
    for (File f : dirs.listFiles()) {
        if (f.exists())
            f.delete();
    success = true;
...
voiddeleteFiles(String dir, String... files)
delete Files
if (!dir.endsWith(File.separator)) {
    dir += File.separator;
for (String file : files) {
    new File(dir + file).delete();
intdeleteFiles(String directory, FileFilter filter, boolean recursive)
Removes all files in the given directory matching the given filter
return deleteFiles(new File(directory), filter, recursive);