#!/opt/bin/perl # ############################################################################### # # # Program to compare all the files in two directories (also recursively) # # # ############################################################################### # # # Version 1.0 - Written 21.11.95 by Steffen Beyer # # # ############################################################################### # # # Usage: diffdir [-r] # # # ############################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ############################################################################### $version = 'version 1.0'; $self = $0; $self =~ s!^.*/!!; if ($ARGV[0] eq "-r") { shift; $recursive = 1; } if (@ARGV != 2) { die "Usage: $self [-r] \n"; } $directory1 = shift; $directory2 = shift; unless (-d $directory1) { die "$self: '$directory1' is not a directory!\n"; } unless (-d $directory2) { die "$self: '$directory2' is not a directory!\n"; } unless (-r $directory1) { die "$self: '$directory1' is not readable!\n"; } unless (-r $directory2) { die "$self: '$directory2' is not readable!\n"; } $directory1 =~ s!/$!!; $directory2 =~ s!/$!!; &compare($directory1, $directory2); exit; sub compare { local($source,$target) = @_; local($sourcefile,$targetfile,$rc); # # Get the list of all entries in the source directory: # unless (opendir(DIR,"$source")) { print "$self: can't open directory '$source': $!\n"; return; } # # Slurp them all into an array: # local(@entries) = readdir(DIR); # closedir(DIR); # # Cycle through all directory entries: # for (@entries) { next if ($_ eq '.'); next if ($_ eq '..'); $sourcefile = "$source/$_"; $targetfile = "$target/$_"; if (-d $sourcefile) { if (-e $targetfile) { if (-d $targetfile) { if ($recursive) { &compare($sourcefile, $targetfile); } next; } else { print "$self: can't compare directory '$sourcefile' with file '$targetfile'!\n"; next; } } else { print "$self: no corresponding '$targetfile' for '$sourcefile'!\n"; next; } } elsif (-f $sourcefile) { if (-f $targetfile) { print "$self: comparing '$sourcefile' with '$targetfile':\n"; unless (open(DIFF,"diff $sourcefile $targetfile 2>/dev/null |")) { print "$self: can't open pipe to read output of 'diff'-command: $!\n"; next; } while () { print; } close(DIFF); next; } elsif (-d $targetfile) { print "$self: can't compare file '$sourcefile' with directory '$targetfile'!\n"; next; } elsif (-e $targetfile) { print "$self: can't compare file '$sourcefile' with special file '$targetfile'!\n"; next; } else { print "$self: no corresponding '$targetfile' for '$sourcefile'!\n"; next; } } else { print "$self: skipping special file '$sourcefile'!\n"; next; } } }