Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use File::Find; # No warnings so the output doesn't state which folders it # can't access (Windows issue) no warnings 'File::Find'; use Digest::MD5; local $| = 1; #**************** File Scope Variables ********************* my $path = $ARGV[0]; my $testpath = 'C:/Temp/'; #*********************************************************** my %files; my $wasted = 0; print "Searching for duplicate files on $ARGV[0]\n"; find(\&check_file, $path); #find(\&check_file, $ARGV[0] || $usbstick); local $" = ","; 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."\ +n"; } foreach my $hash (keys %md5) { next unless @{$md5{$hash}} > 1; print "\n@{$md5{$hash}}"; print "File size $size"; $wasted += $size * (@{$md5{$hash}} - 1); } } 1 while $wasted =~ s/^([-+]?\d+)(\d{3})/$1,$2/; print "\n$wasted bytes in duplicated files\n"; sub check_file { -f && push @{$files{(stat(_))[7]}}, $File::Find::name; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Find duplicate question
by Loops (Curate) on Oct 24, 2014 at 23:06 UTC | |
by Anonymous Monk on Oct 25, 2014 at 13:18 UTC | |
|
Re: File::Find duplicate question
by crashtest (Curate) on Oct 24, 2014 at 23:09 UTC | |
by Anonymous Monk on Oct 25, 2014 at 13:18 UTC | |
|
Re: File::Find duplicate question
by 2teez (Vicar) on Oct 25, 2014 at 02:48 UTC | |
by Anonymous Monk on Oct 25, 2014 at 13:19 UTC | |
by 2teez (Vicar) on Oct 25, 2014 at 17:30 UTC |