Here you can find the source of deletePath(File path)
Parameter | Description |
---|---|
path | The path to delete (normally a folder). |
public static boolean deletePath(File path)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Firestar Software, Inc. * 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:/*from w ww.j a va 2 s . c om*/ * Firestar Software, Inc. - initial API and implementation * * Author: * Gabriel Oancea * *******************************************************************************/ import java.io.*; public class Main { /** * Delete all files and sub-folders of the specified path, and then the specified path itself. All exceptions are * ignored. * * @param path The path to delete (normally a folder). */ public static boolean deletePath(File path) { if (path == null) throw new IllegalArgumentException( "Null path in FileUtil.deletePath()"); boolean ok = true; try { File[] files = path.listFiles(); for (int i = 0; i < files.length && ok; i++) { if (files[i].exists() && files[i].isDirectory()) ok = deletePath(files[i]); } for (int i = 0; i < files.length && ok; i++) { if (files[i].exists() && !files[i].isDirectory()) { ok = files[i].delete(); } } if (ok) { if (!path.delete()) { ok = false; } } } catch (Exception ex) { return false; } return ok; } }