Skip to content

Instantly share code, notes, and snippets.

@capotej
Created March 4, 2012 23:48
Show Gist options
  • Save capotej/1975463 to your computer and use it in GitHub Desktop.
Save capotej/1975463 to your computer and use it in GitHub Desktop.
Cached mkdir -p in scala
// Usage:
// val dircache = new CachedMkdir
// dircache.mkdirp("a/b/c/d/e") // creates the directory structure
// dircache.mkdirp("a/b/c/d/e") // does nothing
// dircache.mkdirp("a/b/Z/Y/Z") // only creates from b/ down
class CachedMkdir {
var cache = Set[String]()
def mkdirp(path: String) {
var prepath = ""
for(dir <- path.split("/")){
prepath += (dir + "/")
if(!cache.contains(prepath)){
new java.io.File(prepath).mkdir()
cache += prepath
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment