public final void dirRemove ( File dir ) throws IOException { if ( dir != null ) { getLog ( ) . debug ( "Deleting tree: " + dir . toString ( ) ) ; //$NON-NLS-1$ final LinkedList < File > candidates = new LinkedList <> ( ) ; candidates . add ( dir ) ; File [ ] children ; final BuildContext buildContext = getBuildContext ( ) ; while ( ! candidates . isEmpty ( ) ) { final File f = candidates . getFirst ( ) ; getLog ( ) . debug ( "Scanning: " + f ) ; //$NON-NLS-1$ if ( f . isDirectory ( ) ) { children = f . listFiles ( ) ; if ( children != null && children . length > 0 ) { // Non empty directory for ( final File c : children ) { getLog ( ) . debug ( "Discovering: " + c ) ; //$NON-NLS-1$ candidates . push ( c ) ; } } else { // empty directory getLog ( ) . debug ( "Deleting: " + f ) ; //$NON-NLS-1$ candidates . removeFirst ( ) ; f . delete ( ) ; buildContext . refresh ( f . getParentFile ( ) ) ; } } else { // not a directory candidates . removeFirst ( ) ; if ( f . exists ( ) ) { getLog ( ) . debug ( "Deleting: " + f ) ; //$NON-NLS-1$ f . delete ( ) ; buildContext . refresh ( f . getParentFile ( ) ) ; } } } getLog ( ) . debug ( "Deletion done" ) ; //$NON-NLS-1$ } }
Delete a directory and its content .