Skip to content

Instantly share code, notes, and snippets.

@polymorphic
Created October 9, 2013 00:26
Show Gist options
  • Save polymorphic/6894163 to your computer and use it in GitHub Desktop.
Save polymorphic/6894163 to your computer and use it in GitHub Desktop.
Delete directory (recursive)
val path = FileSystems.getDefault.getPath(dirName)
if (Files.exists(path) && Files.isDirectory(path)) {
Files.walkFileTree(path, new FileVisitor[Path] {
def visitFileFailed(file: Path, exc: IOException) = FileVisitResult.CONTINUE
def visitFile(file: Path, attrs: BasicFileAttributes) = {
Files.delete(file)
FileVisitResult.CONTINUE
}
def preVisitDirectory(dir: Path, attrs: BasicFileAttributes) = FileVisitResult.CONTINUE
def postVisitDirectory(dir: Path, exc: IOException) = {
Files.delete(dir)
FileVisitResult.CONTINUE
}
})
}
Files.createDirectory(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment