Java Recursive Delete recursiveDeleteNoCheck(File f)

Here you can find the source of recursiveDeleteNoCheck(File f)

Description

recursive Delete No Check

License

Apache License

Declaration

public static boolean recursiveDeleteNoCheck(File f) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    public static boolean recursiveDeleteNoCheck(File f) {
        try {//w  w  w.  j  a v a2s. c  o  m
            if (f.isDirectory()) {
                File[] files = f.listFiles();
                for (int i = 0; i < files.length; i++) {
                    if (!recursiveDeleteNoCheck(files[i])) {

                        return (false);
                    }
                }
                if (!f.delete()) {

                    return (false);
                }
            } else {
                if (!f.delete()) {

                    return (false);
                }
            }
        } catch (Exception ignore) {/* ignore */
        }

        return (true);
    }

    public static boolean isDirectory(String fileName) {
        File testFile = new File(fileName);

        if ((testFile.exists()) && (testFile.isDirectory())) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean delete(File f) {
        if (f.isFile())
            return f.delete();
        else if (f.isDirectory()) {
            boolean b = clearDir(f);
            b &= f.delete();
            return b;
        } else
            return false;
    }

    public static boolean isFile(String fileName) {
        File testFile = new File(fileName);

        if ((testFile.exists()) && (testFile.isFile())) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean clearDir(File dir) {
        if (!dir.isDirectory())
            return false;
        File[] files = dir.listFiles();
        if (files == null || files.length == 0)
            return true;
        boolean cleared = true;
        for (File sub : files) {
            cleared &= delete(sub);
        }
        return cleared;
    }
}

Related

  1. recursiveDelete(String path)
  2. recursiveDeleteFile(File f)
  3. recursiveDeleteFile(File file)
  4. recursiveDeleteFile(File file)
  5. recursiveDeleteHelper(File parent, List failed)
  6. recursiveDeleteNoCheck(File f)
  7. recursiveDeleteOnExit(File parent)
  8. recursiveDeleteOnExit(File rootDir)
  9. recursiveDeleteOnExitHelper(File fileOrDir)