Java Recursive Delete recursiveDelete(File file)

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

Description

Recursively deletes the given file whether its a file or directory returning the number of files deleted

License

Open Source License

Declaration

public static int recursiveDelete(File file) 

Method Source Code

//package com.java2s;
/**/* w w  w  .j a v  a2 s. co  m*/
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.io.File;

public class Main {
    /**
     * Recursively deletes the given file whether its a file or directory returning the number of files deleted
     */
    public static int recursiveDelete(File file) {
        int answer = 0;
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (files != null) {
                for (File child : files) {
                    answer += recursiveDelete(child);
                }
            }
        }
        if (file.delete()) {
            answer += 1;
        }
        return answer;
    }
}

Related

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