Click here to Skip to main content
12,749,754 members (37,582 online)
Click here to Skip to main content
Add your own
alternative version


132 bookmarked
Posted 10 Aug 2008

Duplicate Files Finder

, 15 Dec 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A utility to find any duplicate file in your hard drives using MD5 hashing.


Search results


File deleted


Once a year, I do that terrific job of cleaning files I created or downloaded on my drives. The last time I tried to do it, it was such a fastidious task that I thought of doing that thing semi-automatically. I needed some free utility that could find duplicate files, but I found none that corresponded to my needs. I decided to write one.


The CRC calculation method is available here. I use the MD5 hashing provided by the standard libraries. I added an event to the MD5 computing method so as to get a hashing progression, it is a thread that reads the stream position while the MD5 computing method is reading the same stream.

Using the code

The utility uses two main classes, DirectoryCrawler and Comparers. The use is obvious :) Please notice that instead of iterating through a list list.count X list.count times, DuplicateFinder uses a Hashtable that contains the pair <size,count>. Once populated, all files with count =1 will be removed: (Very much faster!!!!)

int len = filesToCompare.Length;
List<long> alIdx = new List<long>();
System.Collections.Hashtable HLengths = new System.Collections.Hashtable();
foreach (FileInfo fileInfo in filesToCompare)
    if (!HLengths.Contains(fileInfo.Length))
        HLengths.Add(fileInfo.Length, 1);
        HLengths[fileInfo.Length] = (int)HLengths[fileInfo.Length] + 1;
foreach (DictionaryEntry hash in HLengths)
    if ((int)hash.Value == 1)
        setText(stsMain, string.Format("Will remove File with size {0}", hash.Key));
FileInfo[] fiZ = new FileInfo[len - alIdx.Count];
int j = 0;
for (int i = 0; i < len; i++)
    if (!alIdx.Contains(filesToCompare[i].Length))
        fiZ[j++] = filesToCompare[i];
return fiZ;

Points of interest

  • (Done) Optimizes file moving, UI may be unresponsive while moving big files :(.
  • (Useless, my MD5 is better ^_^) Add options to choose between CRC32 and MD5 hashing.
  • Maybe use an XML configuration file. At this time, moving duplicate files to D:\DuplicateFiles (which is hard coded, viva Microsoft!) and skipping that folder during scanning is sufficient to me.
  • Don't forget that your posts make POIs.
  • (Done): Code an event enabled MD5 hashing class that would report hashing progression, imagine hashing a 10 GB file!


  • v0.2
    • Optimized duplicates retrieving (duplicate sizes and duplicate hashes).
    • Added Move to Recycle Bin.
    • Added file size criteria.
    • Files to delete info updated for every check/uncheck in listview.
    • Added colors and fonts to UI.
    • Debug enabled sources (#if DEBUG synchronous #else threaded).
    • Added List<Fileinfo> and List<string[]> instead of using array lists.
    • MD5 hashing is used instead of CRC32 (supercat9).
    • Added Skip Source Folder option.
    • Added Drop SubFolder.
    • Some optimizations...
  • v0.1
    • First time publishing. Waiting for bug reports :)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chief Technology Officer
Morocco Morocco
in his studies, erratum discovered c/c++.he appreciated it.
when he met oracle products, in his job, he fell in love.
he uses c# .net & ms sql.

he created a "f.r.i.e.n.d.s" like soap movie, melting all of the above.
went back in the university.
after he took courses of artificial vision & imagery, he finished his studies with a successful license plate recognition project.

You may also be interested in...

Comments and Discussions

PraiseDocumentation Pin
G.Heisenberg29-Jan-17 23:54
memberG.Heisenberg29-Jan-17 23:54 
QuestionDuplicate Files Deleter Pin
Samantha_Chloe18-Aug-16 5:10
memberSamantha_Chloe18-Aug-16 5:10 
QuestionMessage Removed Pin
sashualia9-Jan-16 4:02
membersashualia9-Jan-16 4:02 
QuestionVery good job and many thanks Pin
dede33325-Dec-15 23:49
memberdede33325-Dec-15 23:49 
AnswerRe: Very good job and many thanks Pin
eRRaTuM11-Feb-16 11:22
membereRRaTuM11-Feb-16 11:22 
Questionapp hangs in watchFinished() Pin
Art Psi14-May-15 21:44
memberArt Psi14-May-15 21:44 
QuestionDelete Duplicate Files Pin
bardy114-Oct-14 20:55
memberbardy114-Oct-14 20:55 
AnswerRe: Delete Duplicate Files Pin
eRRaTuM19-Nov-14 16:08
membereRRaTuM19-Nov-14 16:08 
GeneralMy vote of 5 Pin
Midax31-Oct-13 4:39
memberMidax31-Oct-13 4:39 
GeneralRe: My vote of 5 Pin
eRRaTuM28-May-14 4:43
membereRRaTuM28-May-14 4:43 
Generaldup0licate folder Pin
tirmizi1010-Dec-12 4:33
membertirmizi1010-Dec-12 4:33 
GeneralRe: dup0licate folder Pin
eRRaTuM28-May-14 4:42
membereRRaTuM28-May-14 4:42 
Questionsaymahayen Pin
Member 960575916-Nov-12 10:51
memberMember 960575916-Nov-12 10:51 
GeneralMy vote of 5 Pin
manoj kumar choubey6-Jul-12 20:55
membermanoj kumar choubey6-Jul-12 20:55 
GeneralRe: My vote of 5 Pin
eRRaTuM28-May-14 4:40
membereRRaTuM28-May-14 4:40 
QuestionReference to new version Pin
abusa4-Feb-12 22:57
memberabusa4-Feb-12 22:57 
Questionsource code problem Pin
arun116818-Jan-12 15:25
memberarun116818-Jan-12 15:25 
QuestionDuplicate Finder Pin
vernados24-Oct-11 7:07
membervernados24-Oct-11 7:07 
QuestionCrashes when using large number of files? Pin
markus folius10-Jan-11 13:29
membermarkus folius10-Jan-11 13:29 
AnswerRe: Crashes when using large number of files? Pin
eRRaTuM28-May-14 4:46
membereRRaTuM28-May-14 4:46 
QuestionO(N^2) dependency in the listview? Pin
SInsanity5-Dec-10 6:14
memberSInsanity5-Dec-10 6:14 
AnswerRe: O(N^2) dependency in the listview? Pin
eRRaTuM28-May-14 4:25
membereRRaTuM28-May-14 4:25 
GeneralContextSwitchDeadlock was detected Pin
ToothRobber22-Apr-10 5:45
memberToothRobber22-Apr-10 5:45 
GeneralMissing ConsoleTestRestorer & Restorer Pin
Member 28715804-Apr-10 5:20
memberMember 28715804-Apr-10 5:20 
GeneralRe: Missing ConsoleTestRestorer & Restorer Pin
k2ox27-Nov-10 8:06
memberk2ox27-Nov-10 8:06 
GeneralDuplicate File Finder , Name Finder , Zero Lenght etc Pin
stixoffire22-Dec-08 22:25
memberstixoffire22-Dec-08 22:25 
GeneralRe: Duplicate File Finder , Name Finder , Zero Lenght etc Pin
eRRaTuM23-Dec-08 3:37
membereRRaTuM23-Dec-08 3:37 
GeneralRe: Duplicate File Finder , Name Finder , Zero Lenght etc Pin
Booya10014-Jan-09 13:35
memberBooya10014-Jan-09 13:35 
AnswerRe: Duplicate File Finder , Name Finder , Zero Lenght etc Pin
eRRaTuM14-Jan-09 15:42
membereRRaTuM14-Jan-09 15:42 
GeneralMy vote of 5. Pin
Lion_King110922-Dec-08 18:03
memberLion_King110922-Dec-08 18:03 
GeneralRe: My vote of 5. Pin
eRRaTuM23-Dec-08 3:51
membereRRaTuM23-Dec-08 3:51 
GeneralDuplicate Files Finder. MD5 Encryption Pin
Henry Minute15-Dec-08 6:20
memberHenry Minute15-Dec-08 6:20 
GeneralRe: Duplicate Files Finder. MD5 Encryption Pin
eRRaTuM23-Dec-08 3:49
membereRRaTuM23-Dec-08 3:49 
GeneralHardcoded path causes RTE Pin
At Nel14-Dec-08 18:43
memberAt Nel14-Dec-08 18:43 
GeneralRe: Hardcoded path causes RTE Pin
eRRaTuM15-Dec-08 4:15
membereRRaTuM15-Dec-08 4:15 
Questionthread exception ! any solution?? Pin
Member 551477514-Dec-08 11:40
memberMember 551477514-Dec-08 11:40 
AnswerRe: thread exception ! any solution?? Pin
eRRaTuM15-Dec-08 4:31
membereRRaTuM15-Dec-08 4:31 
GeneralI like it Pin
=Xc@libur=12-Nov-08 18:12
member=Xc@libur=12-Nov-08 18:12 
GeneralRe: I like it Pin
eRRaTuM17-Nov-08 2:52
membereRRaTuM17-Nov-08 2:52 
GeneralDuplicate FIle Name finder Pin
pyrodood9-Sep-08 6:17
memberpyrodood9-Sep-08 6:17 
AnswerRe: Duplicate FIle Name finder Pin
eRRaTuM15-Sep-08 17:25
membereRRaTuM15-Sep-08 17:25 
GeneralRe: Duplicate FIle Name finder [modified] Pin
pyrodood16-Sep-08 5:43
memberpyrodood16-Sep-08 5:43 
Yes that is a solution. However with currently around 8000 files, and the need to check for duplicate names on a daily basis the amount of time involved as well as the high possibility for human error on such a scale proves this solution not viable in my circumstances. Thanks for the thought though.

PS. I've attempted another solution.
Command line I CD to the directory. Use:

DIR /S >1.txt

the /S lists files in the subdirectories.
the >1.txt outputs the returned lines into a text file named 1

Then I imported the file into excel, sort by filename then compare with a logical function if the one is equal to the one underneath it. Then sort by the logic return column and I have a list of duplicate name files.

One problem however, each line does not contain the location of each file, so I have a list but not sure what directories they are in, I can run a search for them.

I thought it would an easy option to add into the program being that it already creates and compares the files the directory and sub-directories.


modified on Tuesday, September 16, 2008 11:16 AM

GeneralRe: Duplicate FIle Name finder Pin
supercat915-Dec-08 7:29
membersupercat915-Dec-08 7:29 
GeneralRe: Duplicate FIle Name finder Pin
pyrodood15-Dec-08 8:18
memberpyrodood15-Dec-08 8:18 
GeneralGreat article Pin
final_zero1-Sep-08 10:09
memberfinal_zero1-Sep-08 10:09 
AnswerRe: Great article Pin
eRRaTuM15-Sep-08 17:34
membereRRaTuM15-Sep-08 17:34 
GeneralRe: Great article Pin
final_zero19-Sep-08 10:01
memberfinal_zero19-Sep-08 10:01 
GeneralRe: Great article Pin
eRRaTuM22-Sep-08 5:55
membereRRaTuM22-Sep-08 5:55 
QuestionCaching? Pin
GregSawin1-Sep-08 8:35
memberGregSawin1-Sep-08 8:35 
AnswerRe: Caching? Pin
eRRaTuM15-Sep-08 17:42
membereRRaTuM15-Sep-08 17:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 15 Dec 2008
Article Copyright 2008 by eRRaTuM
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid