[feca22]: diff_dir  Maximize  Restore  History

Download this file

33 lines (26 with data), 710 Bytes

#!/usr/bin/perl -w
#
# diff_dir [old_dir] [new_dir]
#
# Will look in the new_dir for new files or changed ones and then copy
# them over to the new dir.

$diff = '/usr/bin/diff -bBN';
my $dir_old = shift;
my $dir_new = shift;
my $copy    = shift || 0;

unless (-d $dir_old and -d $dir_new) { die "Usage $0 [old_dir] [new_dir]\n"; }

my @new_files = sort glob("$dir_new/*");

foreach my $f (@new_files) {
    my $file = $f;
    $file =~ s/$dir_new\///;

    if (! -r "$dir_old/$file") {
        print "$file new.\n";
        $d = 1;
    } else {
        $d = `$diff $f $dir_old`;
    }

    if ($d !~ /^\s*$/) {
        print "$f diffs. \n" unless $d eq '1';
        print `cp -f $f $dir_old` if $copy;
    }
}