wrinkles has asked for the wisdom of the Perl Monks concerning the following question:
I have near-duplicate files in deeply nested directories. The duplicates are appended with " 1" as in "Mack the Knife 1.mp3". The duplicates are found together in the same directories. I would like to be able to locate potential duplicates (with regex), then check to see if a counterpart (without the " 1" is located in the directory. If the counterpart exists, rename. If not, then it's not a "duplicate", so do nothing. The best I can do is find the " 1.mp3" files and move them. How can I check for the counterpart? TIA.
#!/usr/bin/perl -w use strict; use File::Find; find(\&process, '/Users/Shared/Music'); sub process { if (/[\d\D]*(?<!No\.)\s+1.mp3$/) { rename "$File::Find::name", "/Users/wrinkles/dupes/$_" or die $!; print "$File::Find::name removed. \n"; } }
The regex checks for a trailing " 1" that is not preceded with "No.". If I can check against the counterpart file, the look-behind check for "No." won't be necessary.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Remove (nearly) duplicate files recursively
by moritz (Cardinal) on May 19, 2008 at 09:27 UTC | |
by linuxer (Curate) on May 19, 2008 at 09:48 UTC | |
by wrinkles (Pilgrim) on May 19, 2008 at 10:22 UTC | |
Re: Remove (nearly) duplicate files recursively
by pc88mxer (Vicar) on May 19, 2008 at 15:48 UTC |