public static boolean deleteDirectory(File file, String s, boolean flag, boolean flag1) { if (file == null) { return false; } if (!file.exists() || !file.isDirectory()) { return false; } boolean flag3 = true; File[] f = file.listFiles(); for (int i = 0; i < f.length; i++) { if (f[i].isFile()) { if (s == null || f[i].getName().toLowerCase().endsWith("." + s.toLowerCase())) { flag3 = deleteFile(f[i]); if (!flag3) break; } } else { if (!flag1) { flag3 = deleteDirectory(f[i], true); if (!flag3) break; } } } if (!flag3) { Logger.e(TAG, "delete directory file: " + file.getAbsolutePath()); } else if (flag) { if (file.delete()) { return true; } else { Logger.e(TAG, "delete directory file: " + file.getAbsolutePath()); } } else { return true; } return false; }
public static void copy(File source, File target) throws IOException { if (source != null && !source.exists()) { Logger.e(TAG, "the source file is not exists: " + source.getAbsolutePath()); } else if (source.isFile()) { copyFile(source, target); } else { copyDirectory(source, target); } }