I have several thousand duplicate files (jar files as an example) that I'd like to use powershell to
- Search through the file system recursively
- Find the dups (either by name only or a checksum method or both)
- Delete all duplicates but one.
I'm new to powershell and am throwing this out there to the PS folks that might be able to help.
try this:
from: http://n3wjack.net/2015/04/06/find-and-delete-duplicate-files-with-just-powershell/
Even though the question is old, I have been in a need to clean up all duplicate files based on content. The idea is simple, the algorithm for this is not straightforward. Here is the code which accepts a parameter of "path" to delete duplicates from.
The script
a) Lists all ChildItems
b) Retrieves FileHash from them
c) Groups them by Hash Property (so all the same files are in the single group)
d) Filters out the already-unique files (count of group -eq 1)
e) Loops through each group and lists all but last paths - ensuring one file of each "Hash" always stays
f) Warns before preceding, saying how many files are there in total and how many are going to be deleted.
Probably not the most performance-wise option (SHA1-ing every file) but ensures the file is a duplicate. Works perfectly fine for me :)
Keep a dictionary of files, delete when the next file name was already encountered before:
I used file name as a key, but you can use a checksum if you want (or both) - see code comment.
Instead of just remove your duplicates files, you can replace by a shortcut