Skip to content

Instantly share code, notes, and snippets.

@pathikrit
Last active December 12, 2018 19:50
Show Gist options
  • Save pathikrit/abfa20e8d9dc8a231758b08e28c35ff7 to your computer and use it in GitHub Desktop.
Save pathikrit/abfa20e8d9dc8a231758b08e28c35ff7 to your computer and use it in GitHub Desktop.
Move duplicate files to a directory
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