Java File Path Delete deleteRecursive(File path)

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

Description

This function will recursivly delete directories and files.

License

Open Source License

Parameter

Parameter Description
path File or Directory to be deleted

Return

true indicates success.

Declaration

public static boolean deleteRecursive(File path) 

Method Source Code

//package com.java2s;
/*/* w  w  w  .j a  va 2 s. c  om*/
 * Copyright by AGYNAMIX(R). All rights reserved. 
 * This file is made available under the terms of the
 * license this product is released under.
 * 
 * For details please see the license file you should have
 * received, or go to:
 * 
 * http://www.agynamix.com
 * 
 * Contributors: agynamix.com (http://www.agynamix.com)
 */

import java.io.File;

public class Main {
    /**
     * This function will recursivly delete directories and files.
     * 
     * @param path
     *          File or Directory to be deleted
     * @return true indicates success.
     */
    public static boolean deleteRecursive(File path) {
        if ((path.exists()) && (path.isDirectory())) {
            File[] files = path.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isDirectory()) {
                        deleteRecursive(files[i]);
                    } else {
                        files[i].delete();
                    }
                }
            }
        }
        return (path.delete());
    }
}

Related

  1. deletePath(final File path)
  2. deletePathRecursive(File path)
  3. deleteQuietly(Object path)
  4. deleteRecursive(File path)
  5. deleteRecursive(File path)
  6. deleteRecursive(File path)
  7. deleteRecursive(File path)
  8. deleteRecursive(File path)
  9. deleteRecursive(File path, boolean debug)