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

booleandeleteDirectory(File path)
Delete recursively a directory.
boolean result = true;
if (path.exists()) {
    File[] files = path.listFiles();
    if (files == null) {
        return path.delete();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
...
booleandeleteDirectory(File path)
delete Directory
if (path.exists()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteDirectory(files[i]);
        } else {
            files[i].delete();
return (path.delete());
booleandeleteDirectory(File path)
Deletes a directory and its files recursively.
File[] files = path.listFiles();
for (File file : files) {
    try {
        if (file.isDirectory()) {
            boolean ok = deleteDirectory(file);
            if (!ok) {
                System.out.println("  ups, " + file.getCanonicalPath() + " cannot be deleted");
        } else {
            boolean ok = file.delete();
            if (!ok) {
                System.out.println("  ups, " + file.getCanonicalPath() + " cannot be deleted");
    } catch (IOException e) {
        e.printStackTrace();
return (path.delete());
voiddeleteDirectory(File path)
Convenience function to delete a directory.
if (!path.exists())
    return;
final File[] files = path.listFiles();
if (files != null) {
    for (File file : files) {
        if (file.isDirectory())
            deleteDirectory(file);
        else if (!file.delete()) {
...
booleandeleteDirectory(File path)
Force deletion of directory
if (path.exists()) {
    File[] files = path.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            deleteDirectory(file);
        } else {
            file.delete();
return (path.delete());
voiddeleteDirectory(File path)
delete Directory
if (!path.isDirectory())
    throw new IOException("Directory '" + path + "' does not exist or is not a directory.");
if (path.isDirectory()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteDirectory(files[i]);
        } else {
...
booleandeleteDirectory(File path)
delete Directory
if (path.exists()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteDirectory(files[i]);
        } else {
            files[i].delete();
return (path.delete());
booleandeleteDirectory(File path)
delete Directory
boolean deleted = deleteDirectoryInternal(path);
log.info(deleted ? "Delete succeeded for path: " + path : "Delete failed for path: " + path);
return deleted;
booleandeleteDirectory(File path)
Delete a non-empty directory Copied from http://www.rgagnon.com/javadetails/java-0483.html
boolean succeeded = true;
if (path.exists()) {
    File[] files = path.listFiles();
    if (files != null) {
        for (int i = 0; succeeded && (i < files.length); i++) {
            if (files[i].isDirectory()) {
                succeeded &= deleteDirectory(files[i]);
            } else {
...
booleandeleteDirectory(File path)
Rercursively deletes a directory
if (path == null || !path.exists()) {
    return false;
if (!path.isDirectory()) {
    return path.delete();
boolean res = true;
for (File file : path.listFiles()) {
...