Created
January 18, 2019 15:07
-
-
Save sdaclin/2b752ae8c991750a75f6187161e34911 to your computer and use it in GitHub Desktop.
Will find and print recursively duplicated files in some dirs (comparison based on fileName + Size)
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment