-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_duplicate_nohash.pl
49 lines (41 loc) · 1008 Bytes
/
find_duplicate_nohash.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use Digest::MD5;
# Store all results
my @result = ();
# find_duplicated(@dir_list)
sub find_duplicated(@)
{
my @dir_list = @_;
if ($#dir_list < 0) {
return (undef);
}
my @files;
# Here is the list of files under the the @dir_list array
# Polulate @files here.
# My MD5 Hash
my %md5;
# Loop on what we find by md5
foreach my $file (@files){
next if $file =~ /^\.\.?$/;
open(FILE, $file) or next;
binmode(FILE);
push @{$md5{Digest::MD5->new->addfile(*FILE)->hexdigest}}, $file;
close (FILE);
}
foreach my $hash (keys %md5){
if ( $#{$md5{$hash}} >= 1 ) {
push (@result, [@{$md5{$hash}}]);
}
}
return @result
}
my @duplicated_files = find_duplicated(@ARGV);
foreach my $cur_dump (@duplicated_files){
print("Duplicated files:\n");
foreach my $curl_file (@$cur_dump){
print ("\t$curl_file\n");
}
}