Java File Path Delete deleteDir(File path)

Here you can find the source of deleteDir(File path)

Description

delete Dir

License

Open Source License

Declaration

public static boolean deleteDir(File path) 

Method Source Code


//package com.java2s;
/*//  w ww .  ja v  a2  s .c  om
 * This file is part of SimpleClans2 (2012).
 *
 *     SimpleClans2 is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     SimpleClans2 is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with SimpleClans2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *     Last modified: 10.10.12 21:57
 */

import java.io.File;

public class Main {
    public static boolean deleteDir(File path) {

        if (path == null || !path.isDirectory()) {
            return false;
        }

        File[] files = path.listFiles();
        for (File file : files) {

            if (file.isDirectory()) {
                deleteDir(file);
            }

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

        return path.delete();
    }
}

Related

  1. deleteDir(File f)
  2. deleteDir(File f)
  3. deleteDir(File f)
  4. deleteDir(File fDir)
  5. deleteDir(File file)
  6. deleteDir(File path)
  7. deleteDir(File path)
  8. deleteDir(File path)
  9. deleteDir(final String path)