Last active
December 12, 2018 19:50
-
-
Save pathikrit/abfa20e8d9dc8a231758b08e28c35ff7 to your computer and use it in GitHub Desktop.
Move duplicate files to a directory
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
import better.files._ | |
def moveDupes( | |
dir: File, | |
logFile: File = (File.home / "dupes.txt"), | |
dupeFolder: File = (File.home / 'dupes).createDirectory() | |
) = { | |
for { | |
log <- logFile.printWriter() | |
(hash, toKeep :: toMove) <- dir.listRecursively.toSeq.groupBy(_.md5).mapValues(_.toList) | |
_ = log.println(s"Hash=$hash has multiple files. Keeping $toKeep and moving $toMove") | |
} toMove.foreach(_.moveToDirectory(dupeFolder)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment