Guest User

Untitled

a guest
Jan 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package fr.sdaclin.dedup
  2.  
  3. import java.io.File
  4.  
  5. /**
  6. * Will find recursively duplicated files in some dirs (comparison based on fileName + Size)
  7. */
  8. fun main(args: Array<String>) {
  9. println("I'm working...")
  10.  
  11. findDuplicates(File("/firstDir"), File("/optionalSecondDir"))
  12. .forEach {
  13. val listDuplicated = it.value.joinToString(prefix = "\n\t", separator = "\n\t") { it.file.absolutePath }
  14. println("${it.key}" + listDuplicated)
  15. }
  16. }
  17.  
  18. fun findDuplicates(vararg dirToProceed: File): Map<String, List<DupFile>> {
  19. return dirToProceed.fold(emptySequence<File>()) { acc, file ->
  20. acc + file
  21. .walkTopDown()
  22. .filter { it.isFile }
  23. }
  24. .map { DupFile(it, it.name, it.length()) }
  25. .groupBy { it.name + "-" + it.size }
  26. .filter { it.value.size > 1 }
  27. }
  28.  
  29. class DupFile(val file: File, val name: String, val size: Long)
Add Comment
Please, Sign In to add comment