File-frigging, part II

Chris Benson chrisb at jesmond.demon.co.uk
Thu Aug 21 11:54:00 CDT 2003


So what we want to do is:

- find files that only differ in CaSe

- remove the oldest, keep the newest

(the vendor who ships this cr*p doesn't know what the 'correct' case
should be ... they intend to ship XXXXX.xxx in future: we'll see.)

So:-

#!/usr/bin/perl -wl

# gather the evidence
my %f;
foreach my $file (<*>) {
        $f{lc $file}{$file} = (stat $file)[9];	# store the last-modified
}

foreach my $file (keys %f) {
        next    if scalar keys %{ $f{$file} } == 1; # look for dups

        # find the newest
        my($new, @old) = 
		sort { $f{$file}{$b} <=> $f{$file}{$a} } keys %{ $f{$file} };

        # print an audit trail
        print "# keeping $new ", scalar localtime $f{$file}{$new};
        print "rm $_\t# ", scalar localtime $f{$file}{$_}
                foreach @old;
}

-- 
Chris Benson



More information about the Tyneside-pm mailing list