Skip to content

Instantly share code, notes, and snippets.

@psttf
Last active December 20, 2015 06:39
Show Gist options
  • Save psttf/6087924 to your computer and use it in GitHub Desktop.
Save psttf/6087924 to your computer and use it in GitHub Desktop.
Concatenates all files in current directory and subdirectories, inserting filename before each new file. Set to process only .scala files by default.
import java.io.File
import scala.io._
import scala.util.matching.Regex
def recursiveListFiles(f: File, r: Regex): Array[File] = {
val these = f.listFiles
val good = these.filter(f => r.findFirstIn(f.getName).isDefined)
good ++ these.filter(_.isDirectory).flatMap(recursiveListFiles(_,r))
}
val f = new File(".")
val files = recursiveListFiles(f,""".*\.scala$""".r)
val result = files.flatMap(f => List(
"", "",
"/**",
" * file " + f.getPath,
" */", "",
Source.fromFile(f, "utf-8").mkString
)) mkString "\n"
val printer = new java.io.PrintWriter("out1.scala","utf-8")
printer println result
printer.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment