Skip to content

Instantly share code, notes, and snippets.

@Wizmann
Created February 13, 2013 16:44
Show Gist options
  • Save Wizmann/4945957 to your computer and use it in GitHub Desktop.
Save Wizmann/4945957 to your computer and use it in GitHub Desktop.
计算代码行数的程序
object LineCounter {
def main(args : Array[String]) = {
val code_exts = Set("cc", "java", "cpp", "c", "py", "cxx", "hs", "scala", "scl")
def walk(f: java.io.File): Int = {
val list = f.listFiles()
var tot = 0
list foreach { (x) =>
if(x.getName contains "模版"){}
else if(x.isFile()) {
val ext = x.getName lastIndexOf('.') match {
case -1 => ""
case pos:Int => x.getName.substring(pos + 1).toLowerCase.toString
}
if(code_exts.contains(ext)) {
println(x getName)
tot += scala.io.Source.fromFile(x, "latin1").getLines.size
}
}
else tot += walk(x)
}
tot
}
println("Total Line : " + walk(new java.io.File(".")))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment