Created
March 4, 2012 23:48
-
-
Save capotej/1975463 to your computer and use it in GitHub Desktop.
Cached mkdir -p in scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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