Java Recursive Delete recursiveDeleteOnExit(File parent)

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

Description

Recursively delete parent folder on exit of JVM

License

Open Source License

Parameter

Parameter Description
parent a parameter

Declaration

static public final void recursiveDeleteOnExit(File parent) 

Method Source Code

//package com.java2s;
/*//  ww  w.ja va  2 s .  com
 * 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 {
    /**
     * Recursively delete parent folder on exit of JVM
     * 
     * @param parent
     */
    static public final void recursiveDeleteOnExit(File parent) {
        parent.deleteOnExit();
        if (parent.isDirectory()) {
            File[] files = parent.listFiles();
            for (int ifile = 0; ifile < files.length; ++ifile) {
                if (files[ifile].isDirectory()) {
                    recursiveDeleteOnExit(files[ifile]);
                }
                files[ifile].deleteOnExit();
            }
        }
    }
}

Related

  1. recursiveDeleteFile(File file)
  2. recursiveDeleteFile(File file)
  3. recursiveDeleteHelper(File parent, List failed)
  4. recursiveDeleteNoCheck(File f)
  5. recursiveDeleteNoCheck(File f)
  6. recursiveDeleteOnExit(File rootDir)
  7. recursiveDeleteOnExitHelper(File fileOrDir)
  8. recursivelyDelete(File aDirectory)
  9. recursivelyDelete(File dir)