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 boolean makeDirectory(String dirPath) {
    File file = new File(dirPath);
    return file.mkdirs() || file.isDirectory();
}

From source file:Main.java

public static long getFolderSize(File file) throws Exception {
    long size = 0;
    File[] fileList = file.listFiles();
    for (File f : fileList) {
        if (f.isDirectory()) {
            size += getFolderSize(f);/*from  w  ww.  j  a va2s  .c  o m*/
        } else {
            size += f.length();
        }
    }
    return size;
}

From source file:Main.java

private static boolean deleteDir(File dir) {
    if (dir != null && 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   w w w  . j  a  v a 2 s  . co  m*/
        }
    }
    return dir.delete();
}

From source file:Main.java

private static long getFileSize(File file) {
    long size = 0;
    for (File subFile : file.listFiles()) {
        if (subFile.isDirectory()) {
            size += getFileSize(subFile);
        } else {/*from   w  w  w  .j ava2  s  . c  o  m*/
            size += subFile.length();
        }
    }
    return size;
}

From source file:Main.java

/**
 * checks if the file exists and is readable
 *//*  ww w .j  a v  a  2  s  .com*/
public static boolean fileExistsAndCanRead(String filePath) {
    File f = new File(filePath);
    return (f.exists() && !f.isDirectory() && f.canRead());
}

From source file:Main.java

private static void addFiles(File root, Vector<String> files) {
    if (root == null)
        return;// ww w.  j  a v a2  s  .  co  m
    File[] listFiles = root.listFiles();
    if (listFiles == null)
        return;
    for (File f : listFiles) {

        if (f.isDirectory())
            addFiles(f, files);
        else if (f.getName().endsWith(".pfy"))
            files.add(f.getAbsolutePath());

    }

}

From source file:Main.java

public static long getFileSize(File file) {
    long size = 0;
    for (File subFile : file.listFiles()) {
        if (subFile.isDirectory()) {
            size += getFileSize(subFile);
        } else {/*from ww w .j  av a 2s  .com*/
            size += subFile.length();
        }
    }
    return size;
}

From source file:Main.java

synchronized public static int clearFolder(File path) {
    int deletedItems = 0;
    File[] fileList = path.listFiles();
    if (fileList != null) {
        for (File file : fileList) {
            if (file.isDirectory()) {
                deletedItems += clearFolder(file);
            }// w w w  . jav a2s .c  om
            if (file.delete()) {
                deletedItems++;
            }
        }
    }
    return deletedItems;
}

From source file:Main.java

private static void iterateFolder(File folder, List<File> files) {
    File flist[] = folder.listFiles();
    files.add(folder);/*from   w w w  .ja v  a 2 s. com*/
    if (flist == null || flist.length == 0) {
        files.add(folder);
    } else {
        for (File f : flist) {
            if (f.isDirectory()) {
                iterateFolder(f, files);
            } else {
                files.add(f);
            }
        }
    }
}

From source file:Main.java

private static long calculateDirectorySize(File directory) {
    long result = 0;
    for (File file : directory.listFiles()) {
        if (file.isDirectory()) {
            result += calculateDirectorySize(file);
        } else {//from  w  w  w  . java2  s. co m
            result += file.length();
        }
    }
    return result;
}