Created
September 15, 2011 03:26
-
-
Save benzado/1218456 to your computer and use it in GitHub Desktop.
Remove duplicates (for Mac Downloads folder)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my @FILES = glob('*'); | |
my $X = shift @FILES; | |
my @Xstat = stat($X); | |
my $Xesc = $X; $Xesc =~ s/([^a-zA-Z0-9])/\\$1/g; | |
FILE: foreach my $Y (@FILES) { | |
my @Ystat = stat($Y); | |
$Yesc = $Y; $Yesc =~ s/([^a-zA-Z0-9])/\\$1/g; | |
if ($Xstat[7] == $Ystat[7]) { # files same size? | |
print "Possible match: $X and $Y\n"; | |
my $diffcmd = "diff -q -- $Xesc $Yesc"; | |
# print $diffcmd, "\n"; | |
`$diffcmd`; | |
if ($? == 0) { # files match | |
if ($Xstat[9] < $Ystat[9]) { # pick older file | |
print `mv -v $Yesc ~/.Trash/`; | |
next FILE; # skip end of loop to let $X "win" | |
} | |
print `mv -v $Xesc ~/.Trash`; | |
} | |
} | |
$X = $Y; | |
@Xstat = @Ystat; | |
$Xesc = $Yesc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment