Deleting Duplicate Files Programmatically

Last week I downloaded Mix 09 videos from Mix 09 Videos Online and that was around 7 GB. As we are distributing Mix 09 DVDs on our upcoming INETA user group meeting of Emerging .NET Devs, so what I did is that I selected and copied some videos into another folder and burn that folder in DVDs. And that was great, work done! πŸ™‚

As a result of that, I have duplicate data which was taking some GBs on my laptop HD. Also I don’t want to delete the folder with selected videos as I may need to burn again. So I concluded that I need to have intersection of two folders to avoid duplication. There were more than 60 files and I don’t want to manually match the file and delete redundant files.

Why on earth I will do that manually, just write a program of few lines in .NET and done! Hence I wrote a program which perform a kind of intersection of files in two folders πŸ™‚ something like:

string path = @"C:UsersADILDesktopMix 09";
string pathInnerFolder = @"C:UsersADILDesktopMix 09Mix 09";
DirectoryInfo dir = new DirectoryInfo(path);

foreach (var file in dir.GetFiles())
if (File.Exists(pathInnerFolder + "" + file.Name))

It worked! Excellent! I’m becoming Geek πŸ™‚