Skip to content

Instantly share code, notes, and snippets.

@K0NRAD
Last active October 13, 2015 12:55
Show Gist options
  • Save K0NRAD/0e13f0d8667bda4cc74d to your computer and use it in GitHub Desktop.
Save K0NRAD/0e13f0d8667bda4cc74d to your computer and use it in GitHub Desktop.
delete path recursivly
public void removePath(Path path) throws IOException {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw exc;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment