Duplicates.pl: Difference between revisions
Jump to navigation
Jump to search
(Created page with " ==Script== <PRE> # duplicates.pl # # Dave Saville December 2003 # dave@deezee.org # use strict; use warnings; use File::Find (); if ( ! @ARGV ) { print <<EOF; Finds dupl...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
Perl script | |||
<PRE> | <PRE> | ||
# duplicates.pl | # duplicates.pl | ||
Line 54: | Line 52: | ||
push @{$hash{$_}}, $File::Find::name; | push @{$hash{$_}}, $File::Find::name; | ||
} | } | ||
</PRE> | </PRE> | ||
[[Category: | [[Category:Perl script]] |
Latest revision as of 19:10, 21 October 2017
Perl script
# duplicates.pl # # Dave Saville December 2003 # dave@deezee.org # use strict; use warnings; use File::Find (); if ( ! @ARGV ) { print <<EOF; Finds duplicate file names across disks Just give it a list of disks to search Suggest you point stdout to a file as it can be unexpectably large eg perl duplicates.pl c d >duplicates.txt EOF exit; } my %hash; sub wanted; while ( my $disk = shift ) { File::Find::find({wanted => \&wanted}, join '', substr($disk, 0, 1), ":/."); } foreach $_ (sort keys %hash) { next if @{$hash{$_}} == 1; print "$_\n"; foreach my $thing (@{$hash{$_}}) { print "\t$thing\n"; } } exit; sub wanted { # build a hash of arrays of file locations keyed # by lower cased file names # tr/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; # lower case push @{$hash{$_}}, $File::Find::name; }