Sunday, February 20, 2011

Detecting and Moving Duplicate Files with Perl

I had used iTunes the wrong way, and it auto-generated numerous duplicate copies of my music files within my music folders (song.m4a, song 1.m4a, song 2.m4a, etc...).  Manually deleting those files would have been extremely tedious as the duplicates were spread out across multiple nested folders within my Music directory.

I decided to teach myself Perl this weekend.
My goal was not really to master Perl as much as it was to solve this very specific problem I had created for myself.

Perl is... interesting, to say the least.
If coding wars happened ONLY on battlegrounds of string and file manipulations
... and success was measured ONLY by the number of verbs per keystroke
... then Perl would be far superior to C++.

The program I wrote to move all duplicated files out into another folder for manual deletion lives here:

I wrote a second program to move non-mp3 files (*.wma and *.m4a) if an mp3 with matching filename was found:

Today, I also learned that servers do not like it when you post files with a .pl extension.

Special thanks goes out to the internet Perl community... Who taught me how to program in Perl without the need for any book purchases.

I used Strawberry Perl... because strawberries are pretty.