public static void deleteRecursive ( Path start , boolean deleteStart ) throws IOException { Files . walkFileTree ( start , new SimpleFileVisitor < Path > ( ) { @ Override public FileVisitResult visitFile ( Path file , BasicFileAttributes attrs ) throws IOException { Files . delete ( file ) ; return FileVisitResult . CONTINUE ; } @ Override public FileVisitResult postVisitDirectory ( Path dir , IOException e ) throws IOException { if ( e == null ) { if ( deleteStart || ! Files . isSameFile ( dir , start ) ) { Files . delete ( dir ) ; } return FileVisitResult . CONTINUE ; } else { // directory iteration failed throw e ; } } } ) ; }
Deletes files and folders at the specified path .