Skip to content

Instantly share code, notes, and snippets.

@SebDeclercq
Created July 23, 2014 09:36
Show Gist options
  • Save SebDeclercq/39b7fccb4fa788e5903e to your computer and use it in GitHub Desktop.
Save SebDeclercq/39b7fccb4fa788e5903e to your computer and use it in GitHub Desktop.
#! /usr/bin/perl -w
use strict;
use warnings;
use feature 'say';
use File::Slurp;
use File::Find::Rule;
use Digest::SHA1;
my $dir = $ARGV[0];
chdir $dir
or die "Je ne peux pas changer de dossier ($dir) : $!";
my $ffr = File::Find::Rule->new;
$ffr->file;
my @files = $ffr->in('.');
my (%sha1s,$i);
for (@files) {
$i++;
sha1sum($_,\%sha1s,$i);
}
for (sort keys %sha1s) {
next if $sha1s{$_}{count} <= 1;
my @files = split(';',$sha1s{$_}{files});
say "Les fichiers suivants sont identiques :";
say join("\n",@files);
say "---" x 10;
}
sub sha1sum {
my ($file,$sha1s,$i) = @_;
my $fh;
unless ( open $fh, $file ) {
warn "Je ne peux pas traiter le fichier $file : $!";
next;
}
my $sha1 = Digest::SHA1->new;
$sha1->addfile($fh);
my $sum = $sha1->hexdigest;
$$sha1s{$sum}{count}++;
$$sha1s{$sum}{files} .= $file.';';
close $fh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment