Duplicates.pl

From OS2World.Com Wiki
Revision as of 15:53, 4 March 2016 by Martini (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


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;
}