Here you can find the source of deleteFolder(String folder)
Parameter | Description |
---|---|
filename | the pathname of the folder to erase. |
true
if and only if the folder is successfully deleted; false
otherwise.
public static boolean deleteFolder(String folder)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013-2015 UAH Space Research Group. * 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 * * Contributors:/* ww w .j ava 2s .c o m*/ * MICOBS SRG Team - Initial API and implementation ******************************************************************************/ import java.io.File; public class Main { /** * Deletes a folder from the file system. The method recursively * deletes the contents of the folder and then the folder itself. * * @param filename the pathname of the folder to erase. * @return <code>true</code> if and only if the folder is * successfully deleted; <code>false</code> otherwise. */ public static boolean deleteFolder(String folder) { File folder2Delete = new File(folder); if (folder2Delete.exists()) { File[] files = folder2Delete.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteFolder(files[i].getPath()); } else { files[i].delete(); } } } return (folder2Delete.delete()); } }