Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.sdaclin.dedup
- import java.io.File
- /**
- * Will find recursively duplicated files in some dirs (comparison based on fileName + Size)
- */
- fun main(args: Array<String>) {
- println("I'm working...")
- findDuplicates(File("/firstDir"), File("/optionalSecondDir"))
- .forEach {
- val listDuplicated = it.value.joinToString(prefix = "\n\t", separator = "\n\t") { it.file.absolutePath }
- println("${it.key}" + listDuplicated)
- }
- }
- fun findDuplicates(vararg dirToProceed: File): Map<String, List<DupFile>> {
- return dirToProceed.fold(emptySequence<File>()) { acc, file ->
- acc + file
- .walkTopDown()
- .filter { it.isFile }
- }
- .map { DupFile(it, it.name, it.length()) }
- .groupBy { it.name + "-" + it.size }
- .filter { it.value.size > 1 }
- }
- class DupFile(val file: File, val name: String, val size: Long)
Add Comment
Please, Sign In to add comment