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 getAllFileAndFolder(File folder, Set<File> all) {
    all.add(folder);//from   ww w  .j ava 2s .c o m
    if (folder.isFile()) {
        return;
    }
    for (File file : folder.listFiles()) {
        all.add(file);
        if (file.isDirectory()) {
            getAllFileAndFolder(file, all);
        }
    }
}

From source file:Main.java

public static List<File> getAll(String path) {
    File file = new File(path);
    if (!file.isDirectory())
        return new ArrayList<File>();
    return Arrays.asList(file.listFiles());
}

From source file:Main.java

public static void copyDirectory(File srcDir, File dstDir) throws IOException {
    if (srcDir.isDirectory()) {
        if (!dstDir.exists()) {
            dstDir.mkdir();/* w  w w. j a va2  s.c  om*/
        }

        String[] children = srcDir.list();
        for (int i = 0; i < children.length; i++) {
            copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i]));
        }
    } else {
        copyFile(srcDir, dstDir);
    }
}

From source file:Main.java

public static void deleteDir(File file) {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            deleteDir(f);/*  ww  w  .  j a v a  2  s .  c o  m*/
        }
    }

    file.delete();
}

From source file:Main.java

public static boolean createNewDirectory(File file) {
    if (file.exists() && file.isDirectory()) {
        return false;
    }/*from ww w. j av a2 s  . co  m*/
    return file.mkdirs();
}

From source file:Main.java

public static boolean createFile(File file) {
    if (file.isDirectory()) {
        file.mkdirs();/*from   w ww  .  j av  a2  s  . c o  m*/
    } else if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
    }
    try {
        file.createNewFile();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:Main.java

private static void _dirChecker(File path, String dir) {
    File f = new File(path, dir);

    if (!f.isDirectory()) {
        f.mkdirs();//ww  w .  ja  va 2 s.c o  m
    }
}

From source file:Main.java

public static File ensureDirExists(File dir) throws IOException {
    if (!(dir.isDirectory() || dir.mkdirs())) {
        throw new IOException("Couldn't create directory '" + dir + "'");
    }//from ww  w .  java  2 s . c  om
    return dir;
}

From source file:Main.java

public static void copyDirectory(File srcDir, File dstDir) throws IOException {
    if (srcDir.isDirectory()) {
        if (!dstDir.exists()) {
            dstDir.mkdir();//from  ww w  .  ja  v  a  2 s. c om
        }

        String[] children = srcDir.list();
        for (int i = 0; i < children.length; i++) {
            copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i]));
        }
    } else {

        copyFile(srcDir, dstDir);
    }
}

From source file:Main.java

/**
 * Confirms the FTL resources dir exists and contains the dat files.
 *///from   w  w  w.  j ava2  s.c  om
public static boolean isDatsDirValid(File d) {
    if (!d.exists() || !d.isDirectory())
        return false;
    if (!new File(d, "data.dat").exists())
        return false;
    if (!new File(d, "resource.dat").exists())
        return false;
    return true;
}