All,
Just to round this off, I failed to get this to work on my set up so looked around some more and in the end
http://www.perlmonks.org/?node_id=855401 provided me with exactly what I needed.
Had to edit the 1st post following the posters, but here is what worked for me:-
#!/usr/bin/perl
use strict;
use warnings;
use File::Compare;
use File::Find;
#If you want to set a base_directory, you can do so here.
my $base_directory;
print "What directory? ";
my $directory = <>;
chomp $directory;
my %files;
sub files_wanted {
my $raw_file = $File::Find::name;
if ( -f ) {
my ($volume,$directories,$file) = File::Spec->splitpath($raw_file);
#update from a prior suggestion.
my $file_size = -s $raw_file;
push @{$files{"$file ($file_size bytes)"}}, $raw_file;
}
}
#If you set a base directory above, you will need to change
find(\&files_wanted,$directory);
open (MYFILE, '>>dupes.txt');
#This section searches the hash for any file with 2 or more files which share the same filename.ext and size.
#After that, it compares all of the files with those attributes to determine if they share the same contents.
#It will print the list of files with the same filename and size and will tell you which ones share the same
#contents.
for my $file (sort keys %files) {
if (@{$files{$file}} > 1) {
my $amount = @{$files{$file}};
print (MYFILE) "$file\t\t$amount\n";
for my $location1 (@{$files{$file}}) {
print (MYFILE) "\t$location1\n";
for my $location2 (@{$files{$file}}) {
unless ($location1 eq $location2) {
if (compare($location1,$location2) == 0) {
print (MYFILE) "\t\tExact copy: $location2\n";
}
}
}
}
print (MYFILE) "\n";
}
}
close (MYFILE);