public static boolean deleteDir ( File dir ) { if ( dir . isDirectory ( ) ) { String [ ] children = dir . list ( ) ; for ( String file : children ) { boolean success = deleteDir ( new File ( dir , file ) ) ; if ( ! success ) { return false ; } } } // The directory is now empty so delete it return dir . delete ( ) ; }
If a deletion fails the method stops attempting to delete and returns false .