forked from jdegoes/blueeyes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.scala
20 lines (18 loc) · 866 Bytes
/
count.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import scala.annotation.tailrec
import java.io._
def getFileAndByteCount(srcDir: File) = {
@tailrec
def getFileAndByteCountAcc(dirList: Array[File], fileCount: Long, byteCount: Long): Tuple2[Long, Long] = {
val (files, subDirs) = dirList.partition(_.isFile)
val classFiles = files.filter(f => f.getName.endsWith(".class"))
val newFileCount = fileCount + classFiles.size
val newByteCount = byteCount + classFiles.map { f => f.length.toLong }.foldLeft(0l) { (a, b) => a + b }
if (subDirs.isEmpty)
(fileCount, byteCount)
else
getFileAndByteCountAcc(subDirs.flatMap(d => d.listFiles), newFileCount, newByteCount)
}
getFileAndByteCountAcc(srcDir.listFiles, 0l, 0l)
}
val (fileCount, byteCount) = getFileAndByteCount(new File("target/test_classes"))
println("Total files: " + fileCount + ", size: " + byteCount + " bytes.")