Java File Path Delete deleteDir(File delDir)

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

Description

Util: Deletes recursively the given directory.

License

Apache License

Parameter

Parameter Description
delDir The directory to delelte

Return

true if the directory is successfully deleted; false otherwise

Declaration

public static boolean deleteDir(File delDir) 

Method Source Code

//package com.java2s;
/*// w  ww.j ava 2s . c om
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 *
 * Copyright (C) 2006-2010 Adele Team/LIG/Grenoble University, France
 */

import java.io.File;

public class Main {
    /**
       * Util: Deletes recursively the given directory.
       * 
       * @param delDir
       *            The directory to delelte
       * @return true if the directory is successfully deleted; false otherwise
       */
    public static boolean deleteDir(File delDir) {
        if (!delDir.exists())
            return true;

        File[] allDelFiles = delDir.listFiles();

        if (allDelFiles != null)
            for (int iF = 0; iF < allDelFiles.length; iF++) {
                if (allDelFiles[iF].isDirectory())
                    deleteDir(allDelFiles[iF]);
                else
                    allDelFiles[iF].delete();
            }

        return delDir.delete();
    }
}

Related

  1. deleteChildDirectoriesExcept(File path, String... directoriesToSkip)
  2. deleteContents(File dirPath, List failures)
  3. deleteContentsOnly(final String srcPath)
  4. deleteDataFiles(final Collection paths)
  5. deleteDb(String path)
  6. deleteDir(File dir)
  7. deleteDir(File dir)
  8. deleteDir(File dir)
  9. deleteDir(File dir)