Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Duplicate File Finder
#1


Here's a duplicate file finder perl script that i've modified a few times. It will look through files of a similar size and compare them by looking through their MD5 hashes to find duplicate files. This is VERY useful if you have copies of music or something within a same directory but with a different name, because this will detect those copies, and you can delete them manually to free up some space on your hard drive.

I didn't make it to automatically remove files just so that you have the option yourself to decide whether or not to delete them.

Code:
#!/usr/bin/perl -w

use strict;
use File::Find;
use Digest::MD5;

my %files;
my $wasted = 0;
find(\&check_file, $ARGV[0] || ".");

local $" = "\n";
foreach my $size (sort {$b <=> $a} keys %files) {
  next unless @{$files{$size}} > 1;
  my %md5;
  foreach my $file (@{$files{$size}}) {
    open(FILE, $file) or next;
    binmode(FILE);
    push @{$md5{Digest::MD5->new->addfile(*FILE)->hexdigest}},$file;
  }
  foreach my $hash (keys %md5) {
    next unless @{$md5{$hash}} > 1;
    print "\n";
    print "\n";
    print "($size bytes) Duplicate Files:\n";
    print "@{$md5{$hash}}\n";
    print "\n";
    $wasted += $size * (@{$md5{$hash}} - 1);
  }
}

1 while $wasted =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
print "\n";
print "######################################################\n";
print "                                                    \n";
print "  You have $wasted bytes total in duplicate files   \n";
print "                                                   \n";
print "######################################################\n";
print "\n";

sub check_file {
  -f && push @{$files{(stat(_))[7]}}, $File::Find::name;
}

Put this in the directory that you want to look though and run it from it's filename within cmd prompt. It will compare files from different folders as well.

Enjoy
Reply


Messages In This Thread
Duplicate File Finder - by AceInfinity - 01-17-2011, 10:17 PM
RE: Duplicate File Finder - by AceInfinity - 01-22-2011, 01:33 AM
RE: Duplicate File Finder - by Caaz - 02-14-2011, 08:53 PM
RE: Duplicate File Finder - by AceInfinity - 02-14-2011, 09:06 PM
RE: Duplicate File Finder - by eax - 04-30-2011, 03:06 AM
RE: Duplicate File Finder - by AceInfinity - 04-30-2011, 01:20 PM
RE: Duplicate File Finder - by Bengan - 05-08-2011, 09:28 AM
RE: Duplicate File Finder - by AceInfinity - 05-08-2011, 01:28 PM
RE: Duplicate File Finder - by andrewgail - 05-14-2011, 11:49 AM
RE: Duplicate File Finder - by AceInfinity - 05-14-2011, 02:58 PM
RE: Duplicate File Finder - by Injection - 05-19-2011, 09:20 PM
RE: Duplicate File Finder - by AceInfinity - 05-20-2011, 01:57 AM
RE: Duplicate File Finder - by Crystal - 05-20-2011, 11:02 AM
RE: Duplicate File Finder - by deleteman - 01-04-2012, 02:08 PM
RE: Duplicate File Finder - by AceInfinity - 01-04-2012, 02:17 PM
RE: Duplicate File Finder - by Yellows - 01-04-2012, 03:22 PM
RE: Duplicate File Finder - by AceInfinity - 01-04-2012, 03:48 PM
RE: Duplicate File Finder - by Yellows - 01-04-2012, 03:51 PM
RE: Duplicate File Finder - by AceInfinity - 01-04-2012, 03:59 PM
RE: Duplicate File Finder - by Yellows - 01-04-2012, 04:01 PM
RE: Duplicate File Finder - by AceInfinity - 01-04-2012, 04:10 PM
RE: Duplicate File Finder - by Yellows - 01-04-2012, 04:12 PM
RE: Duplicate File Finder - by AceInfinity - 01-04-2012, 04:20 PM
RE: Duplicate File Finder - by Yellows - 01-04-2012, 04:25 PM
RE: Duplicate File Finder - by AceInfinity - 01-04-2012, 04:38 PM
RE: Duplicate File Finder - by Yellows - 01-04-2012, 04:40 PM
RE: Duplicate File Finder - by AceInfinity - 01-04-2012, 05:08 PM
RE: Duplicate File Finder - by AceInfinity - 01-05-2012, 01:14 AM
RE: Duplicate File Finder - by brianofen - 11-04-2012, 09:34 AM
RE: Duplicate File Finder - by AnnaLorf - 03-19-2013, 06:08 AM
RE: Duplicate File Finder - by alexias - 05-29-2014, 03:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Admin Page Finder HF~Legend 1 1,305 08-20-2012, 01:33 PM
Last Post: Trump

Forum Jump:


Users browsing this thread: 3 Guest(s)