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

voiddeleteContents(File dirPath, List failures)
Recursive delete files.
String[] ls = dirPath.list();
for (int idx = 0; idx < ls.length; idx++) {
    File file = new File(dirPath, ls[idx]);
    if (file.isDirectory()) {
        deleteContents(file, failures);
    if (!file.delete()) {
        failures.add(file);
...
booleandeleteContentsOnly(final String srcPath)
delete Contents Only
boolean folderDelete = true;
final File srcPathFile = new File(srcPath);
if (null == srcPathFile || !srcPathFile.exists()) {
    folderDelete = false;
} else {
    final String files[] = srcPathFile.list();
    if (files != null) {
        for (int index = 0; index < files.length; index++) {
...
voiddeleteDataFiles(final Collection paths)
Delete all files from collection of paths in String format.
for (String path : paths) {
    File file = new File(path);
    if (file.exists()) {
        file.delete();
    } else {
        throw new IOException("Failed to delete folowing data file :\n" + file.getPath());
voiddeleteDb(String path)
delete Db
File dbdir = new File(path);
if (dbdir.exists()) {
    if (dbdir.isDirectory()) {
        String[] files = dbdir.list();
        int dirs = 0;
        for (int i = 0; i < files.length; i++) {
            File f = new File(path + "/" + files[i]);
            if (f.isFile()) {
...
booleandeleteDir(File delDir)
Util: Deletes recursively the given directory.
if (!delDir.exists())
    return true;
File[] allDelFiles = delDir.listFiles();
if (allDelFiles != null)
    for (int iF = 0; iF < allDelFiles.length; iF++) {
        if (allDelFiles[iF].isDirectory())
            deleteDir(allDelFiles[iF]);
        else
...
voiddeleteDir(File dir)
delete Dir
if (!dir.exists()) {
    return;
for (File e : dir.listFiles()) {
    if (e.isDirectory())
        deleteDir(e);
    else
        delete(e);
...
booleandeleteDir(File dir)
Loescht das angegebene Verzeichnis inkl.
if (dir.isDirectory()) {
    for (File f : dir.listFiles()) {
        if (!deleteDir(f))
            return false;
return dir.delete();
voiddeleteDir(File dir)
utility method to delete a directory
if (dir == null)
    return;
if (dir.isDirectory()) {
    File[] files = dir.listFiles();
    for (File file : files) {
        deleteDir(file);
    dir.delete();
...
booleandeleteDir(File dir)
Delete recursively.
if (!dir.exists())
    return true;
File[] subfiles = dir.listFiles();
if (subfiles.length > 0) {
    for (File f : subfiles) {
        if (f.isFile())
            f.delete();
        else
...
voiddeleteDir(File dir)
Remove the content of the specified directory and remove it
File[] children = dir.listFiles();
if (children == null || children.length == 0) {
    dir.delete();
} else {
    for (File child : children)
        if (child.isDirectory())
            deleteDir(child);
        else
...