Java File Path Delete deleteDirectory(String dir_path)

Here you can find the source of deleteDirectory(String dir_path)

Description

Utilitary method to delete the directory corresponding to the given path

License

Apache License

Parameter

Parameter Description
dir_path - the directory path

Return

boolean - true if directory was succesfully deleted

Declaration

static public boolean deleteDirectory(String dir_path) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2003-2016 Patrick G. Durand
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.//from w  w  w. ja  v a  2  s.  c  om
 */

import java.io.File;

public class Main {
    /**
     * Utilitary method to delete the directory corresponding to the given path
     * 
     * @param dir_path
     *          - the directory path
     * @return boolean - true if directory was succesfully deleted
     */
    static public boolean deleteDirectory(String dir_path) {
        return deleteDirectory(new File(dir_path));
    }

    /**
     * Utilitary method to delete the directory given as parameter
     * 
     * @param dir
     *          - the directory to delete
     * @return boolean - true if directory was succesfully deleted
     */
    public static boolean deleteDirectory(File dir) {
        if (dir.exists()) {
            File[] files = dir.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    files[i].delete();
                }
            }
        }
        return (dir.delete());
    }
}

Related

  1. deleteDirectory(final File path)
  2. deleteDirectory(final File path)
  3. deleteDirectory(final String directoryPath)
  4. deleteDirectory(final String fullDirPath)
  5. deleteDirectory(final String path)
  6. deleteDirectory(String directoryPath)
  7. DeleteDirectory(String directoryPath)
  8. deleteDirectory(String dirPath)
  9. deleteDirectory(String dirPath)