Java Utililty Methods Directory Clean

List of utility methods to do Directory Clean

Description

The list of methods to do Directory Clean are organized into topic(s).

Method

voidcleanDirectory(File currentDir)
Clean directory and it's files
File[] files = currentDir.listFiles();
for (File file : files) {
    file.delete();
currentDir.delete();
StringcleanPath(String loc)
clean Path
if (loc.startsWith("reference:file:")) {
    loc = loc.substring(15);
} else if (loc.startsWith("file:")) {
    loc = loc.substring(5);
} else {
    return loc;
loc = loc.replace("//", "/");
...
StringcleanPath(String path)
cleanPath static method replaces all path separators with system dependednt value.
String str = path.replace('/', File.separatorChar);
String final_str = str.replace('\\', File.separatorChar);
return final_str;
StringcleanPaths(String root, String rel, String name)
clean Paths
String complete = null;
if (root != null) {
    complete = root;
if (rel != null) {
    if (complete != null)
        complete = complete + File.separator + rel;
    else
...
voidclearDir(File dir, boolean clearsubdirs)
clear Dir
if (!dir.exists())
    return;
for (File f : dir.listFiles()) {
    if (f.isDirectory()) {
        if (clearsubdirs) {
            clearDir(f, true); 
            f.delete();
    } else
        f.delete();
voidclearDir(String dirPath)
Deletes all files in the specified directory, recursively.
if (DEBUG) {
    System.out.println("clearDir(" + dirPath + ")");
final File dir = new File(dirPath);
final String[] childList = dir.list();
if (childList == null) {
    return;
for (String childName : childList) {
    final File child = new File(dirPath + "/" + childName);
    if (child.isDirectory()) {
        clearDir(child.getAbsolutePath());
    final boolean didIt = child.delete();
    if (!didIt) {
        throw new RuntimeException("could not delete " + child.getAbsolutePath());