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.
In reply to Remove (nearly) duplicate files recursively by wrinkles
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |