Here you can find the source of deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden)
public static void deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006-2012// w w w .j ava 2 s . c o m * Software Technology Group, Dresden University of Technology * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026 * * 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: * Software Technology Group - TU Dresden, Germany; * DevBoost GmbH - Berlin, Germany * - initial API and implementation ******************************************************************************/ import java.io.File; public class Main { public static void deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden) { if (path.exists()) { File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (deleteHidden || !files[i].getName().startsWith(".")) { if (files[i].isDirectory()) { deleteDirectory(files[i], true, deleteHidden); } else { files[i].delete(); } } } } if (deleteMyself) { path.delete(); } } }