/** * Removes the entire directory tree represented by the parameter, regardless whether it's a file * or directory, whether the directory is empty or not or whether the file or directory is * actually an archive file, an entry in an archive file or not enclosed in an archive file at * all. * * <p>The name of this method is inspired by the Unix command line utility <code>rm</code> with * the <code>-r</code> option to operate recursively. * * <p>This file system operation is <em>not</em> atomic. * * @return Whether or not the entire directory tree was successfully removed. */ public static boolean rm_r(final java.io.File file) { boolean ok = true; if (file.isDirectory()) { // Note that listing the directory this way will cause a recursive // deletion if the directory is actually an archive file. // Although this does not provide best performance (the archive // file could simply be removed like an ordinary file), it ensures // that the state cached by the ArchiveController is not bypassed // and hence prevents a potential bug. java.io.File[] members = file.listFiles(); for (int i = members.length; --i >= 0; ) ok &= rm_r(members[i]); } return ok && file.delete(); }