Advertisement
Guest User

Untitled

a guest
May 21st, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import java.io.File
  2. import java.util.concurrent.atomic.AtomicLong
  3.  
  4. fun walk(vararg files: File, onFile: (File) -> Unit) {
  5. for (file in files) if (file.isDirectory) walk(onFile = onFile, files = *file.listFiles()) else onFile(file)
  6. }
  7.  
  8. val charCount = AtomicLong()
  9. val lineCount = AtomicLong()
  10.  
  11. walk(*File(".").listFiles()) {
  12. when (it.extension) {
  13. "kt", "java" -> {
  14. val text = it.readText()
  15. charCount.addAndGet(text.length.toLong())
  16. lineCount.addAndGet(text.count { it == '\n' }.toLong())
  17. }
  18. }
  19. }
  20.  
  21. println("charCount = $charCount; lineCount = $lineCount")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement