Skip to content

Instantly share code, notes, and snippets.

@hamnis
Last active August 29, 2015 14:19
Show Gist options
  • Save hamnis/833524b24878d52842d5 to your computer and use it in GitHub Desktop.
Save hamnis/833524b24878d52842d5 to your computer and use it in GitHub Desktop.
import java.nio.file._
import java.nio.file.attribute._
object FileIO {
def deleteDirectories(dir: Path): Unit = {
Files.walkFileTree(dir, new SimpleFileVisitor[Path] {
override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
Files.delete(file)
FileVisitResult.CONTINUE
}
override def postVisitDirectory(dir: Path, exc: IOException): FileVisitResult = {
Files.delete(dir)
FileVisitResult.CONTINUE
}
})
Files.deleteIfExists(dir)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment