Java Directory Clean cleanDir(String dir)

Here you can find the source of cleanDir(String dir)

Description

clean Dir

License

Open Source License

Declaration

public static boolean cleanDir(String dir) 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.io.File;

public class Main {
    public static boolean cleanDir(String dir) {
        return deleteDir(new File(dir), false);
    }//from www.  j a  v a 2  s .co m

    public static boolean deleteDir(String dir) {
        return deleteDir(new File(dir), true);
    }

    public static boolean deleteDir(File dir, boolean deleteSelf) {
        if (dir.isDirectory()) {
            String[] children = dir.list();

            for (String child : children) {
                boolean success = deleteDir(new File(dir, child), true);
                if (!success) {
                    return false;
                }
            }
        }

        if (deleteSelf) {
            return dir.delete();
        } else {
            return true;
        }
    }
}

Related

  1. cleanDir(File directory)
  2. cleanDir(final File dir)
  3. cleanDir(final File dir)
  4. cleanDir(final File dir, final String exclude)
  5. cleanDir(final String luceneDir)
  6. cleanDir(String directory)
  7. cleanDir(String path)
  8. cleanDirectory(File currentDir)
  9. cleanPath(String loc)