Java Utililty Methods File Path Delete

List of utility methods to do File Path Delete

Description

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

Method

voiddeleteAllFiles(Vector filesToDelete)
delete All Files
for (int i = 0; i < filesToDelete.size(); i++) {
    ((File) filesToDelete.get(i)).delete();
FiledeleteAllFilesAux(String input, File swapFolder)
Deletes all files in inputFolder backing them up in swapFolder.
File result = null;
File file = new File(input);
if (file.exists()) 
    if (file.isDirectory()) 
        File originalFolder = file; 
        File swap = null;
...
voiddeleteAllFilesIn(String dir)
delete All Files In
List<File> files = getAllFilesIn(dir);
for (int i = 0; i < files.size(); i++) {
    files.get(i).delete();
booleandeleteAllFilesInDir(File dir)
delete All Files In Dir
if (dir.isDirectory()) {
    boolean result = true;
    File[] filelist = dir.listFiles();
    for (int i = 0; i < filelist.length; i++) {
        result &= deleteAllFilesInDir(filelist[i]);
    return result;
} else {
...
booleandeleteAllFilesInDirectory(String path)
deletes entire contents of a folder.
File folder = new File(path);
if (folder != null && folder.exists() && folder.isDirectory()) {
    File[] files = folder.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            files[i].delete();
    return true;
return false;
voiddeleteAllFilesOnlyInDirectory(File startingDir)
delete All Files Only In Directory
File[] filesToDelete = startingDir.listFiles();
if (filesToDelete != null) {
    for (int i = 0; i < filesToDelete.length; i++) {
        if (filesToDelete[i].isFile() && !filesToDelete[i].delete())
            System.out.println("Unable to delete file: " + filesToDelete[i].getPath());
voiddeleteAllFilesRecursively(String directoryName)
delete All Files Recursively
File dir = new File(directoryName);
if (dir.exists()) {
    deleteAllFilesRecursively(dir);
    dir.delete();
StringdeleteAndCreateFolder(String path)
delete And Create Folder
boolean success_del;
File folder = new File(path);
success_del = deleteDirectory(folder);
if (!success_del) {
    throw new IOException();
File newFolder = new File(path);
if (newFolder.mkdir() == true) {
...
intdeleteBlankPath(String path)
delete Blank Path
File f = new File(path);
if (!f.canWrite()) {
    return 1;
if (f.list() != null && f.list().length > 0) {
    return 2;
if (f.delete()) {
...
voiddeleteChildDirectoriesExcept(File path, String... directoriesToSkip)
delete Child Directories Except
if (path.isDirectory()) {
    for (File child : path.listFiles()) {
        String name = child.getName();
        if (child.isDirectory()) {
            boolean skip = false;
            for (String directoryToSkip : directoriesToSkip) {
                if (name.equalsIgnoreCase(directoryToSkip)) {
                    skip = true;
...