-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathFileRegisters.scala
More file actions
39 lines (31 loc) · 993 Bytes
/
FileRegisters.scala
File metadata and controls
39 lines (31 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package utility
import java.io.{File, FileWriter}
object FileRegisters {
var files: Seq[(String, String, () => String)] = Nil
def add(filename: String, contents: => String): Unit = {
add("", filename, contents)
}
def add(filedir:String, filename:String, contents: => String) :Unit = {
val fn = () => contents
files = (filedir, filename, fn) +: files
}
def contains(filename: String): Boolean = {
files.count(_._2 == filename) != 0
}
def write(fileDir: String = "./build", filePrefix: String = ""): Unit = {
files.foreach { case (fd, fn, fc) =>
writeOutputFile(fileDir, fd, filePrefix + fn, fc())
}
}
def writeOutputFile(td: String, fd: String, fn:String, fc: String): File = {
val dirStr = if(fd == "") td else s"$td/$fd"
val dir = new File(dirStr)
if(!dir.exists()) require(dir.mkdirs())
val fname = s"$dirStr/$fn"
val f = new File(fname)
val fw = new FileWriter(f)
fw.write(fc)
fw.close()
f
}
}