Example usage for java.io File isDirectory

List of usage examples for java.io File isDirectory

Introduction

In this page you can find the example usage for java.io File isDirectory.

Prototype

public boolean isDirectory() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a directory.

Usage

From source file:Main.java

public static void deleteFile(File file) {
    if (file.isDirectory()) {
        if (file.list().length == 0)
            file.delete();//  w w w  .  j a  v  a 2  s  . c om
        else {
            File[] files = file.listFiles();
            for (File f : files)
                deleteFile(f);
            deleteFile(file);
        }
    } else
        file.delete();
}

From source file:Main.java

public static void deleteRecursive(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory())
        for (File child : fileOrDirectory.listFiles())
            deleteRecursive(child);//w  w w. j a  v a 2  s.  co  m

    fileOrDirectory.delete();
}

From source file:Main.java

private static boolean deleteDir(File dir) {
    if (dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }/*from ww  w. ja  va 2s  . c om*/
        }
    }
    // The directory is now empty so delete it
    return dir.delete();
}

From source file:Main.java

public static void deleteRecursive(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory())
        for (File child : fileOrDirectory.listFiles()) {
            deleteRecursive(child);/*  w  ww . j av a  2s. co  m*/
        }

    fileOrDirectory.delete();
}

From source file:Main.java

public static void deleteEmptyDir(File file) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null && files.length > 0) {
            for (File tempFile : files) {
                deleteEmptyDir(tempFile);
                deleteEmptyDir(tempFile);
            }/*from ww  w. j a v  a  2 s. c  o m*/
        } else {
            file.delete();
        }
    }
}

From source file:Main.java

public static void deleteFolder(File f) {
    File[] files = f.listFiles();
    for (File fi : files) {
        if (fi.isDirectory()) {
            deleteFolder(fi);//  w ww  .  java  2 s  .com
        }
        fi.delete();
    }
}

From source file:Main.java

public static void ensureDirExists(File dir) {
    if (!dir.exists() || !dir.isDirectory()) {
        dir.mkdirs();/*  w ww.  ja  v a  2s  . com*/
    }
}

From source file:Main.java

private static void deleteFileOrDirectory(File file) {
    if (file.isDirectory()) {
        File[] subFiles = file.listFiles();
        for (File sf : subFiles) {
            if (sf.isFile()) {
                sf.delete();/*from   w ww  . j  a v a  2s . c om*/
            } else {
                deleteFileOrDirectory(sf);
            }
        }
    }
    file.delete();
}

From source file:Main.java

public static void deleteDir(File file) {
    if (file.isDirectory()) {
        for (File _file : file.listFiles()) {
            if (_file.isDirectory()) {
                deleteDir(_file);// ww  w.j a  v a  2s.  com
            } else {
                _file.delete();
            }
        }
    } else {
        file.delete();
    }
}

From source file:Main.java

public static void delete(final File dir) {
    if (dir.isDirectory()) {
        final File[] files = dir.listFiles();
        if (null != files && files.length > 0) {
            for (final File file : files) {
                delete(file);/*from   w w w  . j  a  va2 s . c  o  m*/
            }
        }
    }
    dir.delete();
}