Java Recursive Delete recursiveDeleteHelper(File parent, List failed)

Here you can find the source of recursiveDeleteHelper(File parent, List failed)

Description

recursive Delete Helper

License

Open Source License

Declaration

private static void recursiveDeleteHelper(File parent, List<File> failed) 

Method Source Code


//package com.java2s;
/*/*  w w w.j  ava 2 s  . c  o m*/
 * $Id$
 *
 * Copyright (c) 2008 by Joel Uckelman
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License (LGPL) as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, copies are available
 * at http://www.opensource.org.
 */

import java.io.File;

import java.io.IOException;

import java.util.List;

public class Main {
    private static void recursiveDeleteHelper(File parent, List<File> failed) {
        // delete children, depth first
        if (parent.isDirectory()) {
            for (File child : parent.listFiles()) {
                recursiveDeleteHelper(child, failed);
            }
        }

        // store leaves which can't be deleted in the failed list
        if (!parent.delete())
            failed.add(parent);
    }

    /**
     * Deletes a file.
     *
     * @param file the file to delete
     * @throws IOException if the file cannot be deleted
     */
    public static void delete(File file) throws IOException {
        if (!file.delete())
            throw new IOException("Failed to delete " + file.getAbsolutePath());
    }
}

Related

  1. recursiveDelete(String p_path, boolean p_deletemetoo)
  2. recursiveDelete(String path)
  3. recursiveDeleteFile(File f)
  4. recursiveDeleteFile(File file)
  5. recursiveDeleteFile(File file)
  6. recursiveDeleteNoCheck(File f)
  7. recursiveDeleteNoCheck(File f)
  8. recursiveDeleteOnExit(File parent)
  9. recursiveDeleteOnExit(File rootDir)