Java Directory Clean clearDir(File dir, boolean clearsubdirs)

Here you can find the source of clearDir(File dir, boolean clearsubdirs)

Description

clear Dir

License

Open Source License

Declaration

static public void clearDir(File dir, boolean clearsubdirs) 

Method Source Code

//package com.java2s;
/* Copyright 2012, UCAR/Unidata.
 See the LICENSE file for more information.
 *//*from   ww  w.  java  2  s.  c  o m*/

import java.io.*;

public class Main {
    static public void clearDir(File dir, boolean clearsubdirs) {
        // wipe out the dir contents
        if (!dir.exists())
            return;
        for (File f : dir.listFiles()) {
            if (f.isDirectory()) {
                if (clearsubdirs) {
                    clearDir(f, true); // clear subdirs
                    f.delete();
                }
            } else
                f.delete();
        }
    }
}

Related

  1. cleanDir(String path)
  2. cleanDirectory(File currentDir)
  3. cleanPath(String loc)
  4. cleanPath(String path)
  5. cleanPaths(String root, String rel, String name)
  6. clearDir(String dirPath)