Java Recursive Delete recursiveDelete(File parent)

Here you can find the source of recursiveDelete(File parent)

Description

recursive Delete

License

Open Source License

Parameter

Parameter Description
parent a parameter

Return

boolean

Declaration

static public final boolean recursiveDelete(File parent) 

Method Source Code

//package com.java2s;
/*//from  w  w w .j  av  a 2  s.  co  m
 * Copyright (c) 2012 Diamond Light Source Ltd.
 *
 * All rights reserved. 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 {
    /**
     * @param parent
     * @return boolean
     */
    static public final boolean recursiveDelete(File parent) {

        if (parent.exists()) {
            if (parent.isDirectory()) {

                File[] files = parent.listFiles();
                for (int ifile = 0; ifile < files.length; ++ifile) {
                    if (files[ifile].isDirectory()) {
                        recursiveDelete(files[ifile]);
                    }
                    if (files[ifile].exists()) {
                        files[ifile].delete();
                    }
                }
            }
            return parent.delete();
        }
        return false;
    }
}

Related

  1. recursiveDelete(File file)
  2. recursiveDelete(File file, boolean deleteParentFile)
  3. recursiveDelete(File fileOrDir)
  4. recursiveDelete(File fileOrDir)
  5. recursiveDelete(File folder)
  6. recursiveDelete(File pathToFolderOrFile)
  7. recursiveDelete(File root)
  8. recursiveDelete(File root)
  9. recursiveDelete(File rootDir, boolean deleteRoot)