Java File Path Delete deleteAllFilesRecursively(String directoryName)

Here you can find the source of deleteAllFilesRecursively(String directoryName)

Description

delete All Files Recursively

License

Open Source License

Declaration

public static void deleteAllFilesRecursively(String directoryName) throws IOException 

Method Source Code

//package com.java2s;
/*/*w  w  w  .ja v  a  2s  .c o  m*/
 * Copyright 2004 by EkoLiving Pty Ltd.  All Rights Reserved.
 *
 * This software is the proprietary information of EkoLiving Pty Ltd.
 * Use is subject to license terms.
 */

import java.io.File;

import java.io.IOException;

public class Main {
    public static void deleteAllFilesRecursively(String directoryName) throws IOException {
        File dir = new File(directoryName);
        if (dir.exists()) {
            deleteAllFilesRecursively(dir);
            dir.delete();
        }
    }

    public static void deleteAllFilesRecursively(File directory) throws IOException {
        File[] files = directory.listFiles();
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            if (file.exists()) {
                if (file.isDirectory()) {
                    deleteAllFilesRecursively(file);
                }
                if (file.delete() == false) {
                    throw new IOException("Unable to delete " + file.getCanonicalPath());
                }
            }
        }
    }
}

Related

  1. deleteAllFilesAux(String input, File swapFolder)
  2. deleteAllFilesIn(String dir)
  3. deleteAllFilesInDir(File dir)
  4. deleteAllFilesInDirectory(String path)
  5. deleteAllFilesOnlyInDirectory(File startingDir)
  6. deleteAndCreateFolder(String path)
  7. deleteBlankPath(String path)
  8. deleteChildDirectoriesExcept(File path, String... directoriesToSkip)
  9. deleteContents(File dirPath, List failures)