List of usage examples for java.io File isDirectory
public boolean isDirectory()
From source file:Main.java
public static void DeleteRecursive(File fileOrDirectory) { boolean bool; if (fileOrDirectory.isDirectory()) for (File child : fileOrDirectory.listFiles()) { bool = child.delete();//from w w w . j a v a 2 s .c om System.out.println(" deleted folder contents > result : " + bool); DeleteRecursive(child); } bool = fileOrDirectory.delete(); System.out.println(" deleted folder > result : " + bool); }
From source file:Main.java
protected static void delFiles(File file, String keep) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (int i = 0, size = files.length; i < size; i++) { File f = files[i]; delFiles(f, keep);/* w w w . j a va 2s . c om*/ } } } else { if (keep.equals(file.getPath())) return; file.delete(); } }
From source file:Main.java
public static boolean DoesFolderExist(String path) { if (path == null) return false; if (path.trim().isEmpty()) return false; File file = new File(path.trim()); return file.exists() && file.isDirectory(); }
From source file:Main.java
/** * Determine whether a file is a ZIP File. *///from ww w.j av a 2 s. c om public static boolean isZipFile(File file) throws IOException { if (file.isDirectory()) { return false; } if (!file.canRead()) { throw new IOException("Cannot read file " + file.getAbsolutePath()); } if (file.length() < 4) { return false; } DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); int test = in.readInt(); in.close(); return test == 0x504b0304; }
From source file:Main.java
private static void dumpFolderRecursive(final File folder, final StringBuilder sb, final int level) { for (int i = 0; i < level; i++) sb.append("\t"); sb.append(folder.getName());//from ww w . j av a 2s .com sb.append("\n"); for (File file : folder.listFiles()) { if (file.isDirectory()) dumpFolderRecursive(file, sb, level + 1); else { for (int i = 0; i <= level; i++) sb.append("\t"); sb.append(file.getName()); sb.append("\n"); } } }
From source file:Utils.java
/** * Deletes a directory.//from ww w . ja v a2s. c o m * * @param dir the file for the directory to delete * @return true if susscess */ public static boolean deleteDir(File dir) { if (dir.isDirectory()) { for (File file : dir.listFiles()) { if (file.isDirectory()) { try { if (file.getCanonicalFile().getParentFile().equals(dir.getCanonicalFile())) { deleteDir(file); if (file.exists() && !file.delete()) { System.out.println("Can't delete: " + file); } } else { System.out.println("Warning: " + file + " may be a symlink. Ignoring."); } } catch (IOException e) { System.out.println("Warning: Cannot determine canonical file for " + file + " - ignoring."); } } else { if (file.exists() && !file.delete()) { System.out.println("Can't delete: " + file); } } } return dir.delete(); } return false; }
From source file:Main.java
public static void mkdirs(File file) throws IOException { if (file.isDirectory()) { return;//from w w w. java2 s . c o m } if (!file.mkdirs()) { if (file.exists()) { throw new IOException("failed to create " + file + " file exists and not a directory"); } throw new IOException(); } }
From source file:Main.java
private static boolean checkFsWritable() { // Create a temporary file to see whether a volume is really writeable. // It's important not to put it in the root directory which may have a // limit on the number of files. String directoryName = Environment.getExternalStorageDirectory().toString() + "/DCIM"; File directory = new File(directoryName); if (!directory.isDirectory()) { if (!directory.mkdirs()) { return false; }/* w w w .j a v a 2s . c om*/ } return directory.canWrite(); }
From source file:Main.java
public static void deleteFile(File f) { if (f.isDirectory()) { File[] files = f.listFiles(); if (files != null && files.length > 0) { for (int i = 0; i < files.length; ++i) { deleteFile(files[i]);/* w ww .ja v a2 s. c o m*/ } } } f.delete(); }
From source file:Main.java
public static void deleteFile(File file) { if (file.exists()) { if (file.isDirectory()) { File[] files = file.listFiles(); for (File subFile : files) { deleteFile(subFile);//from w w w . j a va 2s .c o m } file.delete(); } else { file.delete(); } } }