Java File Path Delete deleteDirectory(File path)

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

Description

Rercursively deletes a directory

License

Open Source License

Parameter

Parameter Description
path The directory's path

Return

True if the delete was ok, false otherwise

Declaration

public static boolean deleteDirectory(File path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 - 2013 by Timotei Dolean <timotei21@gmail.com>
 * /*from  ww  w  .j  av  a  2  s.  co m*/
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

import java.io.File;

public class Main {
    /**
     * Rercursively deletes a directory
     * 
     * @param path
     *        The directory's path
     * @return True if the delete was ok, false otherwise
     */
    public static boolean deleteDirectory(File path) {
        if (path == null || !path.exists()) {
            return false;
        }

        if (!path.isDirectory()) {
            return path.delete();
        }

        boolean res = true;
        for (File file : path.listFiles()) {
            res = res && deleteDirectory(file);
        }
        return res && path.delete();
    }

    /**
     * Rercursively deletes a directory
     * 
     * @param path
     *        The directory's path
     * @return True if the delete was ok, false otherwise
     */
    public static boolean deleteDirectory(String path) {
        return deleteDirectory(new File(path));
    }
}

Related

  1. deleteDirectory(File path)
  2. deleteDirectory(File path)
  3. deleteDirectory(File path)
  4. deleteDirectory(File path)
  5. deleteDirectory(File path)
  6. deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden)
  7. deleteDirectory(File path, boolean includeDir)
  8. deleteDirectory(final File path)
  9. deleteDirectory(final File path)