Created
February 13, 2013 16:44
-
-
Save Wizmann/4945957 to your computer and use it in GitHub Desktop.
计算代码行数的程序
This file contains hidden or 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
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