Here you can find the source of recursiveDelete(String p_path, boolean p_deletemetoo)
Parameter | Description |
---|---|
p_path | String |
p_deletemetoo | boolean |
public static boolean recursiveDelete(String p_path, boolean p_deletemetoo)
//package com.java2s; import java.io.*; public class Main { /**// w w w .j a va2 s .c o m * Recursively delete a directory. BE CAREFUL, this deletes everything * @param p_path String * @param p_deletemetoo boolean * @return boolean */ public static boolean recursiveDelete(String p_path, boolean p_deletemetoo) { if (p_path == null) { return true; } String path = p_path; if (path.endsWith("\\") || path.endsWith("/")) { path = path.substring(0, path.length() - 1); } File f = new File(path); if (f.isFile()) { return p_deletemetoo ? f.delete() : true; } String contents[] = f.list(); int len = contents != null ? contents.length : 0; boolean result = true; for (int i = 0; i < len; i++) { if (!recursiveDelete(path + File.separator + contents[i], true)) { result = false; } } if (p_deletemetoo && !f.delete()) { result = false; } return result; } /** * Is the given name a file ? * @param p_path String * @return boolean */ public static boolean isFile(String p_path) { File f = new File(p_path); return f.isFile(); } }