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:Utils.java

public static void deleteRecursive(File dir) throws IOException {
    if (dir.isDirectory())
        deleteContentsRecursive(dir);/* w  w  w.j  a va  2 s  .  c o  m*/
    if (!dir.delete())
        throw new IOException("Unable to delete " + dir);
}

From source file:Main.java

public static boolean delectFileByDir(File file) {
    if (file != null && file.isDirectory()) {
        String[] files = file.list();
        for (String cach : files) {
            boolean result = delectFileByDir(new File(file, cach));
            if (!result) {
                return false;
            }/*from  w  w w . j a v  a  2s  .  c  o m*/
        }
    }
    return file.delete();
}

From source file:Main.java

public static DefaultMutableTreeNode addNodes(File dir) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(dir);
    for (File file : dir.listFiles()) {
        if (file.isDirectory()) {
            node.add(addNodes(file));/*from w ww. j  a  v a 2 s.co m*/
        } else {
            node.add(new DefaultMutableTreeNode(file));
        }
    }
    return node;
}

From source file:Main.java

protected static void delFiles(File file) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (int i = 0, size = files.length; i < size; i++) {
                File f = files[i];
                delFiles(f);//from   w  w w .j  a v a2s.  c o m
            }
        }
    } else {
        file.delete();
    }
}

From source file:Main.java

public static boolean mkdir(String path) {
    File file = new File(path);
    if (file.isDirectory())
        return true;
    else {//from w ww  .ja va  2  s.  co  m
        boolean creadok = file.mkdirs();
        if (creadok) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:Main.java

public static boolean existFile(String path, String fileName) {
    File filePath = new File(path);
    if (!filePath.isDirectory()) {
        filePath.mkdirs();//from www  .ja v  a 2  s .  c o  m
    }
    File file = new File(fileName);
    if (!file.exists() || !file.isFile()) {
        return false;
    }
    return true;
}

From source file:Main.java

private static void walkTreeAndReturnJARS(File dir, Collection<File> dst) {
    for (File e : dir.listFiles()) {
        if (e.isDirectory())
            walkTreeAndReturnJARS(e, dst);
        else {/* w  w w.  j  a v a  2  s .c om*/
            if (e.getName().toLowerCase().endsWith(".jar")) {
                dst.add(e);
            }
        }
    }
}

From source file:Main.java

public static boolean isDirectoryAvailble(String path) {
    File dir = new File(path);
    return dir.exists() && dir.isDirectory();
}

From source file:Main.java

public static boolean removeDir(File dirFile) {

    if (!dirFile.isDirectory()) {
        return false;
    }/*from w  ww .j a va2s . c  o  m*/
    File files[] = dirFile.listFiles();
    for (int i = 0; i < files.length; i++) {

        if (files[i].isDirectory()) {
            break;
        }

        if (!files[i].delete()) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * //  ww w.  j a v  a  2s.  co m
 * @param f
 */
public static void deleteDir(File f) {
    try {
        if (f.isDirectory()) {
            for (File c : f.listFiles()) {
                deleteDir(c);
            }
        }
        f.delete();
    } catch (Exception e) {

    }
}