List of usage examples for java.io File isDirectory
public boolean isDirectory()
From source file:Main.java
/** * Tests if the directory contains the essential root file for a Daisy book * //from ww w.j a v a 2s . c o m * Currently it's limited to checking for Daisy 2.02 books. * @param folder for the directory to check * @return true if the directory is deemed to contain a Daisy Book, else * false. */ public static boolean folderContainsDaisy2_02Book(File folder) { if (!folder.isDirectory()) { return false; } if (new File(folder, "ncc.html").exists()) { return true; } // Minor hack to cope with the potential of ALL CAPS filename, as per // http://www.daisy.org/z3986/specifications/daisy_202.html#ncc if (new File(folder, "NCC.HTML").exists()) { return true; } return false; }
From source file:Main.java
/** * @param prodFile/*from w w w . j ava 2 s. co m*/ * @return true if a module is inserted and recognized by BMI, false otherwise. */ private static boolean validBMIDeviceRoot(File prodFile) { if (!prodFile.exists() || !prodFile.isDirectory()) { return false; } return prodFile.listFiles().length > 0; }
From source file:Main.java
/** * Deletes the contents of {@code dir}. Throws an IOException if any file * could not be deleted, or if {@code dir} is not a readable directory. *///ww w .j av a2s.c o m public static void deleteContents(File dir) throws IOException { File[] files = dir.listFiles(); if (files == null) { throw new IOException("not a readable directory: " + dir); } for (File file : files) { if (file.isDirectory()) { deleteContents(file); } if (!file.delete()) { throw new IOException("failed to delete file: " + file); } } }
From source file:Main.java
public static void deleteDir(File f) { if (f.exists() && f.isDirectory()) { for (File file : f.listFiles()) { if (file.isDirectory()) deleteDir(file);/*ww w. java 2 s . c o m*/ file.delete(); } f.delete(); } }
From source file:Main.java
/** * deletes all Files and Subfolders in a directory * @param dir target directory/*from ww w .j a va2 s .co m*/ * @return */ public static boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] entries = dir.list(); for (int x = 0; x < entries.length; x++) { File aktFile = new File(dir.getPath(), entries[x]); deleteDir(aktFile); } if (dir.delete()) { return true; } else { return false; } } else { if (dir.delete()) { return true; } else { return false; } } }
From source file:Main.java
/** * Delete every item below the File location * * @param file Location//from ww w . j a va 2s. co m */ public static boolean recursiveDelete(File file) { if (file.isDirectory()) { String[] children = file.list(); if (children == null) return false; for (String child : children) { recursiveDelete(new File(file, child)); } } return file.delete(); }
From source file:Main.java
/** * //from w ww .j av a 2s. c o m * Example usage: * <pre> * SwingUtil.createFileFilter("JEQL script (*.jql)", "jql") * </pre> * @param description * @param extension * @return the file filter */ public static FileFilter createFileFilter(final String description, String extension) { final String dotExt = extension.startsWith(".") ? extension : "." + extension; FileFilter ff = new FileFilter() { public String getDescription() { return description; } public boolean accept(File f) { return f.isDirectory() || f.toString().toLowerCase().endsWith(dotExt); } }; return ff; }
From source file:Main.java
/** * Deletes a given folder directory in the form of a {@link File} * /*from w w w . j a va 2 s . c o m*/ * @param folder The folder to delete. * * @return True if the folder was deleted, false otherwise. */ public static boolean deleteFolder(File folder) { if (folder.isDirectory()) { String[] children = folder.list(); if (children != null) { for (String child : children) { boolean success = deleteFolder(new File(folder, child)); if (!success) return false; } } } return folder.delete(); }
From source file:Main.java
public static File[] listFiles(File f) { File[] list;/*from w ww .j av a 2s.com*/ if (f.isDirectory()) { list = f.listFiles(filter); if (list != null) { Arrays.sort(list, comparator); } } else { list = new File[] {}; } return list; }
From source file:Main.java
public static void deleteFile(File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { deleteFile(new File(dir, children[i])); }/*from www .ja va2 s .co m*/ } dir.delete(); }