Perl file to find duplicate files

#!/usr/bin/perl

use strict ;
use warnings;
use File::Find;
use Data::Dumper;
use Digest::MD5;

my $pth = $ARGV[0];
unless ($pth) {
  print " perl1 path";
  exit ;
}
$\ = $/;
my %size ;
my %unopenfile ;
my %md5;
my @resuts;
my $m5 = Digest::MD5->new;

find( sub {
    return if $_ eq '.' ;
    return  if $_ eq  '..';
    $size {$File::Find::name} = -s if -f ;

    }, $pth ) ;

foreach my $file ( keys %size ){
  next if $size{$file} < 1 ;

  unless (open (f1, "$file") ) {
    $unopenfile{$file}++;
    next ;
  }
  push @{$md5{$m5->addfile(*f1)->hexdigest}}, $file;

  close (f1);
}

foreach my $files ( keys %md5){
  if ($#{$md5{$files}} >= 1){
    push (@resuts, @{$md5{$files}});
  }

}

foreach my $dup (@resuts) {
  print "the duplicate files are $dup"

No comments:

Other Articles

Enter your email address: