List of usage examples for java.io File isDirectory
public boolean isDirectory()
From source file:Main.java
public static void valiFileIsDirectory(File file) throws IllegalArgumentException { if (!file.isDirectory()) { throw new IllegalArgumentException("File:'" + file.getName() + "'does not exist or not directory!"); }//from ww w .j a va 2s .c o m }
From source file:Main.java
private static float getSize(String path, Float size) { File file = new File(path); if (file.exists()) { if (file.isDirectory()) { String[] children = file.list(); for (int fileIndex = 0; fileIndex < children.length; ++fileIndex) { float tmpSize = getSize(file.getPath() + File.separator + children[fileIndex], size) / 1000; size += tmpSize;/* w w w . j a v a2 s. c om*/ } } else if (file.isFile()) { size += file.length(); } } return size; }
From source file:Main.java
public static void deleteDir() { File dir = new File(SDPATH); if (dir == null || !dir.exists() || !dir.isDirectory()) return;// www. j a va2 s .com for (File file : dir.listFiles()) { if (file.isFile()) file.delete(); else if (file.isDirectory()) deleteDir(); } dir.delete(); }
From source file:DirectoryIO.java
/** * /*from w ww . jav a 2 s .c o m*/ * recursivly delete directory * * @param directory */ public static boolean delete(File directory) { boolean result = false; if (directory.isDirectory()) { File[] files = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { delete(files[i]); } files[i].delete(); } result = directory.delete(); } return result; }
From source file:Main.java
public static void delAllFiles(File dir) { if (!dir.exists() || !dir.isDirectory()) { return;//from w ww . ja va 2 s . c om } String dirFullName = dir.getAbsolutePath(); String[] fileList = dir.list(); File tempFile = null; for (int i = 0; i < fileList.length; i++) { if (dirFullName.endsWith(File.separator)) { tempFile = new File(dirFullName + fileList[i]); } else { tempFile = new File(dirFullName + File.separator + fileList[i]); } if (tempFile.isFile()) { tempFile.delete(); } if (tempFile.isDirectory()) { delAllFiles(dirFullName + "/" + fileList[i]); delDir(dirFullName + "/" + fileList[i]); } } }
From source file:Main.java
public static Boolean canWrite(File f) { if (f.isDirectory()) { FileWriter w = null;/* w w w . ja va2 s . c o m*/ String testFilename = f.getPath() + "/.EASYRPG_WRITE_TEST"; try { w = new FileWriter(testFilename); // Permissions are checked on open, but it is Android, better be save w.write("Android >.<"); } catch (IOException e) { return false; } finally { try { if (w != null) { w.close(); } } catch (IOException e) { } } File testFile = new File(testFilename); if (testFile.exists()) { // Does not throw testFile.delete(); } } else { boolean deleteAfter = f.exists(); try { FileWriter w = new FileWriter(f, true); w.close(); } catch (IOException e) { return false; } if (deleteAfter) { f.delete(); } } return true; }
From source file:Main.java
public static void deleteDirectoryTree(File fileOrDirectory) // delete everything in folder - recursively { if (fileOrDirectory.isDirectory()) { for (File child : fileOrDirectory.listFiles()) { deleteDirectoryTree(child);//from w w w . j a v a 2 s. c o m } } fileOrDirectory.delete(); }
From source file:Main.java
public static boolean deleteFolderFile(String filePath, boolean deleteThisPath) { if (!TextUtils.isEmpty(filePath)) { try {// w w w . ja v a 2 s. c o m File file = new File(filePath); if (file.isDirectory()) { File files[] = file.listFiles(); for (int i = 0; i < files.length; i++) { deleteFolderFile(files[i].getAbsolutePath(), true); } } if (deleteThisPath) { if (!file.isDirectory()) { file.delete(); } else { if (file.listFiles().length == 0) { file.delete(); } } } return true; } catch (Exception e) { e.printStackTrace(); } } return false; }
From source file:Main.java
public static File getChronosDir() { String chronosHome = getUserHomeDir() + File.separator + CHRONOS_DIR_NAME; File file = new File(chronosHome); if (!file.exists() || !file.isDirectory()) { file.mkdir();//from w w w. j a v a 2s .c om } return file; }
From source file:Main.java
public static final boolean deleteFolder(String path) { // not recursive if (path != null && storageReady()) { File dir = new File(path); if (dir.exists() && dir.isDirectory()) { File[] files = dir.listFiles(); for (File file : files) { if (!file.delete()) { Log.i(tag, "Failed to delete " + file); }//from w ww.jav a 2s. c om } } return dir.delete(); } else { return false; } }