Java Delete Folder deleteFolder(String name)

Here you can find the source of deleteFolder(String name)

Description

delete Folder

License

Open Source License

Declaration

public static boolean deleteFolder(String name) 

Method Source Code


//package com.java2s;
/*/* ww w  . ja  va 2s. c o m*/
 *  Copyright 2010-2011 the original author or authors.
 *
 *  WebServiceMocker is free software; you can redistribute it and/or modify it under the 
 *  terms of version 2.1 of the GNU Lesser General Public License as published by 
 *  the Free Software Foundation.
 *
 *  WebServiceMocker 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 Lesser General Public License for more details at gnu.org.
 */

import java.io.File;

public class Main {
    public static boolean deleteFolder(String name) {

        File file = new File(name);

        if (file.isDirectory()) {
            deleteFiles(file);
        }

        return file.delete();
    }

    private static void deleteFiles(File file) {
        if (file.listFiles() != null) {
            for (File child : file.listFiles()) {

                if (child.isDirectory()) {
                    deleteFiles(child);
                    child.delete();
                } else {
                    child.delete();
                }
            }
        }
    }
}

Related

  1. deleteFolder(final File folder)
  2. deleteFolder(final File folder)
  3. deleteFolder(final String folder)
  4. deleteFolder(String folder)
  5. deleteFolder(String folder)
  6. deleteFolderContents(File folder)
  7. deleteFolderContents(File folder)
  8. deleteFolderContents(File folder)
  9. deleteFolderIfEmpty(File f)