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

/**
 * Checks if this directory has a file with suffix suffix
 * @param f - directory/*from   ww  w .j  a  va2s. c  o  m*/
 * @return
 */
public static boolean hasFileWithSuffix(File f, String suffix) {
    if (f.isDirectory()) {
        for (String s : f.list()) {
            if (s.endsWith(suffix))
                return true;
        }
        return false;
    } else {
        return false;
    }
}

From source file:Main.java

private static List<Class> findClasses(File directory, String packageName) {
    List<Class> classes = new ArrayList<Class>();
    if (!directory.exists()) {
        return classes;
    }//w ww. j av a  2 s  .c o m
    File[] files = directory.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            assert !file.getName().contains(".");
            classes.addAll(findClasses(file, packageName + "." + file.getName()));
        } else if (file.getName().endsWith(".class")) {
            try {
                classes.add(Class
                        .forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return classes;
}

From source file:Main.java

/**
 * Tests if a folder is a RPG2k Game.//w w w. j  ava 2 s  .  c  om
 * (contains DATABASE_NAME and TREEMAP_NAME)
 *
 * @param dir Directory to test
 * @return true if RPG2k game
 */
public static boolean isRpg2kGame(File dir) {
    if (!dir.isDirectory() || !dir.canRead()) {
        return false;
    }

    boolean databaseFound = false;
    boolean treemapFound = false;

    for (File entry : dir.listFiles()) {
        if (entry.isFile() && entry.canRead()) {
            if (!databaseFound && entry.getName().equalsIgnoreCase(DATABASE_NAME)) {
                databaseFound = true;
            } else if (!treemapFound && entry.getName().equalsIgnoreCase(TREEMAP_NAME)) {
                treemapFound = true;
            }

            if (databaseFound && treemapFound) {
                return true;
            }
        }
    }

    return false;
}

From source file:Main.java

/**
 * Recursive method used to find all classes in a given directory and subdirs.
 *
 * @param directory   The base directory
 * @param packageName The package name for classes found inside the base directory
 * @return The classes/*from w w w.j a v  a2  s .c  o  m*/
 * @throws ClassNotFoundException
 */
private static List findClasses(File directory, String packageName) throws ClassNotFoundException {
    List classes = new ArrayList();
    if (!directory.exists()) {
        return classes;
    }
    File[] files = directory.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            assert !file.getName().contains(".");
            classes.addAll(findClasses(file, packageName + "." + file.getName()));
        } else if (file.getName().endsWith(".class") && !file.getName().contains("$")
                && !file.getName().endsWith("Test.class")) {
            classes.add(file.getName().substring(0, file.getName().length() - 6));
        }
    }
    return classes;
}

From source file:Main.java

private static void deleteContent(File dir, boolean deleteDir) {
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (File file : files) {
                deleteContent(file, true);
            }//from   w  w  w . j  a va 2  s . c om
        }
    }
    if (deleteDir)
        dir.delete();
}

From source file:Main.java

public static File getDir(File parent, String dirName) {
    File file = new File(parent, dirName);
    if (!file.exists() || !file.isDirectory()) {
        file.mkdirs();/*from  ww  w .java  2s .com*/
    }
    return file;
}

From source file:Main.java

public static void dirChecker(String directoryPath) {
    File f = new File(directoryPath);

    if (!f.isDirectory()) {
        f.mkdirs();/*from  ww w.  j  ava 2 s.co m*/
    }
}

From source file:Main.java

public static void deleteDir(File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File subFile : files) {
                if (subFile.isDirectory())
                    deleteDir(subFile);//from  w  w w .  ja  v  a2  s. c o  m
                else
                    subFile.delete();
            }
        }
        file.delete();
    }
}

From source file:Main.java

public static boolean deleteDir(File dir) {
    if (dir != null) {
        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 w w w  .ja  v  a 2 s  .c om
            }
        }
        return dir.delete();
    }
    return true;
}

From source file:Main.java

private static boolean containsTestData(File dir, Pattern filenamePattern) {
    File[] files = dir.listFiles();
    assert files != null;
    for (File file : files) {
        if (file.isDirectory()) {
            if (containsTestData(file, filenamePattern)) {
                return true;
            }//  ww w . ja  v  a  2s  .  co  m
        } else {
            if (filenamePattern.matcher(file.getName()).matches()) {
                return true;
            }
        }
    }
    return false;
}