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 File[] getAppFolders() {
    File odk = new File(getOdkFolder());

    File[] results = odk.listFiles(new FileFilter() {

        @Override/*from w w  w.  j a  v a  2 s.c  o  m*/
        public boolean accept(File pathname) {
            if (!pathname.isDirectory())
                return false;
            return true;
        }
    });

    return results;
}

From source file:Main.java

public static boolean recursiveChmod(File root, int mode) throws Exception {
    boolean success = chmod(root, mode) == 0;
    for (File path : root.listFiles()) {
        if (path.isDirectory()) {
            success = recursiveChmod(path, mode);
        }//from  w w  w  .jav a  2 s . c o m
        success &= (chmod(path, mode) == 0);
    }
    return success;
}

From source file:Main.java

public static void deleteSinglePicture(Context ctx, String path) {
    String params[] = new String[] { path };
    ctx.getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            MediaStore.Images.Media.DATA + " LIKE ?", params);
    File file = new File(path);
    File pFile = file.getParentFile();
    if (pFile != null && pFile.isDirectory()) {
        File files[] = pFile.listFiles();
        if (files == null || files.length == 0) {
            pFile.delete();//  w w  w .  j  a  va  2 s.  c  o m
        }
    }
}

From source file:Main.java

public static boolean checkFilesIsNeedDelete(String path, long intervalTime) {
    File file = new File(path);
    if (file == null && !file.exists()) {
        return false;
    }/*from   w w w  .  java  2  s .co m*/
    if (file.isFile()) {
        deleteFileByIntervalTime(file, intervalTime);
    } else {
        File[] fileList = file.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            File temp = fileList[i];
            if (temp.isDirectory()) {
                checkFilesIsNeedDelete(temp.getAbsolutePath(), intervalTime);
            } else {
                deleteFileByIntervalTime(temp, intervalTime);
            }
        }
    }
    return true;
}

From source file:Main.java

public static JFileChooser generateFileChooser(String description, String... ext) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileFilter(new FileFilter() {
        @Override//from  ww  w  .  ja  v a 2 s. co  m
        public boolean accept(File f) {
            boolean res = f.isDirectory();
            for (String s : ext) {
                res = res || f.getName().endsWith("." + s);
            }
            return res;
        }

        @Override
        public String getDescription() {
            return description;
        }

    });
    return fileChooser;
}

From source file:com.bluexml.tools.miscellaneous.ConvertFileContentIntoJSString.java

protected static void parseFile(File input, String fileNameout) {

    if (input.isDirectory()) {
        File[] listFiles = input.listFiles();
        for (File file2 : listFiles) {
            parseFile(file2, fileNameout);
        }//from ww w .j  a  va2s. c  o  m
    } else {
        File output = new File(input.getParentFile(), input.getName() + "-" + fileNameout);
        writeFiles(input, output);
    }

}

From source file:com.cloudera.sqoop.testutil.DirUtil.java

/**
 * recursively delete a dir and its children.
 * @param dir/*w w w  .  ja  v a2 s . c o  m*/
 * @return true on succesful removal of a dir
 */
public static boolean deleteDir(File dir) {
    if (dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            File f = new File(dir, children[i]);
            boolean success = deleteDir(f);
            if (!success) {
                LOG.warn("Could not delete " + f.getAbsolutePath());
                return false;
            }
        }
    }

    // The directory is now empty so delete it too.
    LOG.debug("Removing: " + dir);
    return dir.delete();
}

From source file:Main.java

public static void deleteDir(File dir) {
    if (!dir.exists())
        return;//from   w ww.  java  2s  .  co  m
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File f : files) {
            deleteDir(f);
        }
        dir.delete();
    } else
        dir.delete();
}

From source file:Main.java

private static long getSizeOfFileOrDirectoryInByte(File fileOrDirectory) {
    if (!fileOrDirectory.exists()) {
        return 0;
    }/* w ww .  ja va2 s. com*/
    if (fileOrDirectory.isFile()) {
        return fileOrDirectory.length();
    }

    File[] contents = fileOrDirectory.listFiles();
    long size = 0;
    for (File file : contents) {
        size += file.isDirectory() ? getSizeOfFileOrDirectoryInByte(file) : file.length();
    }
    return size;
}

From source file:jp.furplag.util.commons.FileUtils.java

private static boolean createNewFile(String filename, boolean printStackTrace) {
    try {//from   w  w  w .ja v  a  2s .co  m
        if (StringUtils.isSimilarToBlank(filename))
            throw new IOException("path must not be empty.");
        String path = normalize(filename);
        File file = new File(path);
        if (file.exists() && file.isDirectory())
            throw new IOException(normalize(file.getAbsolutePath()) + " is directory.");
        path = normalize(file.getAbsolutePath());
        forceMkdir(StringUtils.truncateLast(path, "/.*"));
        if (!file.exists())
            return file.createNewFile();

    } catch (Exception e) {
        if (printStackTrace)
            e.printStackTrace();
    }

    return false;
}