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 isDirectory(File file) {
    return file != null && file.exists() && file.isDirectory();
}

From source file:Main.java

public static long getFolderSize(File f) {
    long size = 0;
    if (f.isDirectory()) {
        for (File file : f.listFiles()) {
            size += getFolderSize(file);
        }/*from w w  w .  j a  va  2s. c  o m*/
    } else {
        size = f.length();
    }
    return size;
}

From source file:Main.java

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

From source file:Main.java

public static boolean debugRmDir(String dir, boolean deleteDirectory) {
    File directory = new File(dir);
    if (directory.isDirectory()) {
        String[] children = directory.list();
        for (String s : children) {
            if (!debugRmDir(dir + File.separator + s, true))
                return false;
        }/*from w w w.j  a  v a  2s .com*/
    }

    return !deleteDirectory || directory.delete();
}

From source file:Main.java

private static long getFolderSize(File file) {
    long size = 0;
    File[] fileList = file.listFiles();
    for (File aFileList : fileList) {
        if (aFileList.isDirectory()) {
            size = size + getFolderSize(aFileList);
        } else {/*from   w  ww  .  java  2 s.com*/
            size = size + aFileList.length();
        }
    }
    return size;
}

From source file:Main.java

public static boolean deleteFile(File f) {
    if (f != null && f.exists() && !f.isDirectory()) {
        return f.delete();
    }/*from   w  ww. j a va2s . com*/
    return false;
}

From source file:Main.java

public static long getFreeSpace(String path) {
    File file = new File(path);
    if (!(file.isDirectory() && file.exists())) {
        file.mkdirs();//from ww  w.  j av a  2  s.  c o  m
        if (file.isDirectory()) {
            return file.getFreeSpace();
        } else {
            return 0L;
        }
    } else {
        return file.getFreeSpace();
    }
}

From source file:Main.java

static boolean isFileOrEmptyDirectory(String path) {
    File f = new File(path);
    if (!f.isDirectory())
        return true;

    String[] list = f.list();/*  ww w  . j  a  v  a2 s .  com*/
    return ((list == null) || (list.length == 0));
}

From source file:Main.java

private static void findJavaFiles(String projectDir, List<String> javaFilePaths) {
    File file = new File(projectDir);
    File[] files = file.listFiles();
    if (files == null || files.length == 0) {
        return;/*from  w w  w. ja v a  2s.  c o  m*/
    }
    for (File f : files) {
        if (f.isDirectory()) {
            findJavaFiles(f.getAbsolutePath(), javaFilePaths);
        } else {
            if (f.getAbsolutePath().endsWith(".java")) {
                javaFilePaths.add(f.getAbsolutePath());
            }
        }
    }
}

From source file:Main.java

/**
 * Delete directory you passed. the directory's child file and directory will be deleted too by recursive exploring.
 *///from   ww w.  j  a v  a  2s.com
public static void deleteAllFiles(File directory) {
    File[] files;

    files = directory.listFiles();
    files = files == null ? new File[0] : files;

    for (File file : files) {
        if (file.isDirectory())
            deleteAllFiles(file);
        else
            file.delete();
    }
    directory.delete();
}