Java File Path Delete deleteDirectoryIncludeContent(String folderPath)

Here you can find the source of deleteDirectoryIncludeContent(String folderPath)

Description

Delete directory including contents

License

Open Source License

Parameter

Parameter Description
folderPath folder path

Exception

Parameter Description
IOException an exception

Declaration

public static void deleteDirectoryIncludeContent(String folderPath) throws IOException 

Method Source Code

//package com.java2s;
/**//from   w  w w . jav a2  s  .  c o m
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

import java.io.*;

public class Main {
    /**
     * Delete directory including contents
     * @param folderPath folder path
     * @throws IOException
     */
    public static void deleteDirectoryIncludeContent(String folderPath) throws IOException {
        deleteDirectoryIncludeContent(new File(folderPath));
    }

    private static void deleteDirectoryIncludeContent(File f) throws IOException {
        if (f.isDirectory()) {
            File[] files = f.listFiles();
            if (files != null) {
                for (File c : files) {
                    deleteDirectoryIncludeContent(c);
                }
            }
        }
        if (!f.delete()) {
            throw new FileNotFoundException("Failed to delete : " + f);
        }
    }
}

Related

  1. deleteDirectory(String sPath)
  2. deleteDirectoryAndContents(final File srcPath)
  3. deleteDirectoryAndContentsRecursive(final File srcPath, final boolean deleteSrcDir)
  4. deleteDirectoryContents(File path)
  5. deleteDirectoryContents(String directoryPath, boolean deleteChildDirectories)
  6. deleteDirectoryInternal(File path)
  7. deleteDirectoryRecursively(File path)
  8. deleteDirectoryRecursivly(String path)
  9. deleteDirectoryTree(String directoryPath)