Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active August 29, 2015 14:16
Show Gist options
  • Save frgomes/bbefd9ae01bfa32f7a57 to your computer and use it in GitHub Desktop.
Save frgomes/bbefd9ae01bfa32f7a57 to your computer and use it in GitHub Desktop.
Scala - String to an absolute File
object FileSystemConverters extends FileSystemConverters
trait FileSystemConverters {
import java.io.File
implicit class RichOptionString2OptionFile(path: Option[String]) {
implicit def asFile: Option[File] =
Option(
path
.getOrElse(".")
.asFile)
}
implicit class RichString2File(path: String) {
implicit def asFile: File =
new File(
path
.replaceFirst(
"^~",
System.getProperty("user.home")))
.getAbsoluteFile
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment