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:Compress.java

/** Zip the contents of the directory, and save it in the zipfile */
public static void zipDirectory(String dir, String zipfile) throws IOException, IllegalArgumentException {
    // Check that the directory is a directory, and get its contents
    File d = new File(dir);
    if (!d.isDirectory())
        throw new IllegalArgumentException("Not a directory:  " + dir);
    String[] entries = d.list();/*from w w  w  . j  a v  a2 s .  co m*/
    byte[] buffer = new byte[4096]; // Create a buffer for copying
    int bytesRead;

    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));

    for (int i = 0; i < entries.length; i++) {
        File f = new File(d, entries[i]);
        if (f.isDirectory())
            continue;//Ignore directory
        FileInputStream in = new FileInputStream(f); // Stream to read file
        ZipEntry entry = new ZipEntry(f.getPath()); // Make a ZipEntry
        out.putNextEntry(entry); // Store entry
        while ((bytesRead = in.read(buffer)) != -1)
            out.write(buffer, 0, bytesRead);
        in.close();
    }
    out.close();
}

From source file:Main.java

private static void removeDirectory(File directory) {
    if (directory.isDirectory()) {
        File[] files = directory.listFiles();

        for (int i = 0; i < files.length; ++i) {
            if (files[i].isDirectory()) {
                removeDirectory(files[i]);
            }//  ww w . j  av a  2s .c o m

            files[i].delete();
        }

        directory.delete();
    }

}

From source file:Main.java

public static int deleteFiles(Collection<File> files) {
    int n = 0;//from w w  w. j a va 2  s  .  c  o m
    for (File file : files) {
        if (file.isDirectory()) {
            n += deleteFiles(Arrays.asList(file.listFiles()));
        }
        if (file.delete())
            n++;
    }
    return n;
}

From source file:Main.java

private static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (String aChildren : children) {
            boolean success = deleteDir(new File(dir, aChildren));
            if (!success) {
                return false;
            }/*w ww  .j a  v a  2 s.  c om*/
        }
    }
    return dir != null && dir.delete();
}

From source file:Main.java

public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] childFiles = dir.list();
        for (String s : childFiles) {
            boolean success = deleteDir(new File(dir, s));
            if (success == false) {
                return false;
            }//from   www .  j  a v  a 2  s.c om
        }
    }
    return dir.delete();
}

From source file:Main.java

public static boolean isFileExists(String fileName) {
    File f = new File(PATH + fileName);
    return f.isDirectory();
}

From source file:Utils.java

private static void deleteContentsRecursive(File file) throws IOException {
    File[] files = file.listFiles();
    for (File child : files) {
        if (child.isDirectory())
            deleteContentsRecursive(child);
        if (!child.delete())
            throw new IOException("Unable to delete " + child.getPath());
    }// w  w w.  ja v a  2  s. co m
}

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  ww  . jav  a  2s .c om*/
        }
    }
    return dir != null && dir.delete();
}

From source file:Main.java

private static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (String aChildren : children) {
            boolean success = deleteDir(new File(dir, aChildren));
            if (!success) {
                return false;
            }//from   w ww.ja  v  a2s .  c o  m
        }
    }
    return dir.delete();
}

From source file:Main.java

private static void deleteFile(File file) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            deleteFile(files[i]);//w ww.  ja  v a 2 s . c om
        }
    }
    file.delete();
}