Java File Path Delete deleteDir(File dir, boolean deleteSelf)

Here you can find the source of deleteDir(File dir, boolean deleteSelf)

Description

delete Dir

License

Open Source License

Declaration

public static boolean deleteDir(File dir, boolean deleteSelf) 

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 deleteDir(String dir) {
        return deleteDir(new File(dir), true);
    }// w  w w .j a  va  2  s  .c om

    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. deleteDir(File dir)
  2. deleteDir(File dir)
  3. deleteDir(File dir)
  4. deleteDir(File dir)
  5. deleteDir(File dir, boolean deleteRoot)
  6. deleteDir(File dir, int depth, boolean deleteRootDirectory)
  7. deleteDir(File dir, String dirPath)
  8. deleteDir(File directory)
  9. deleteDir(File directory)