Here you can find the source of deleteDir(File dir)
Parameter | Description |
---|---|
dir | - path to directory to delete |
static boolean deleteDir(File dir)
//package com.java2s; /*-// w w w.ja v a 2 s. c o m * Copyright 2012 Diamond Light Source Ltd. * * 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 */ import java.io.File; public class Main { /** * Helper function to (recursively) delete a directory and all its contents * * @param dir * - path to directory to delete * @return - boolean True if directory no longer exists */ static boolean deleteDir(File dir) { if (!dir.exists()) { return true; } if (dir.isDirectory()) { String[] children = dir.list(); for (String element : children) { boolean success = deleteDir(new File(dir, element)); if (!success) { System.out.println("1. deleteDir could not delete: " + new File(dir, element)); return false; } } } if (dir.delete()) { return true; } System.out.println("2. deleteDir could not delete: " + dir + ". Make sure each test creates a uniquely named folder. Otherwise stale NFS locks may prevent folder deletion."); return false; } }