#!/bin/perl -w # Author: Kevin P. Inscoe . # File: vario # Date of creation: October 16, 2003. # Warranty: None expressed or implied. # License: The Open Software License. V1.1 http://www.opensource.org/licenses/osl.php # # OSI Certified Open Source Software. http://www.opensource.org/licenses/ # # Prerequisites: Perl 5.004 (minimum). # # Purpose: Compares the contents of two directories specified on the command line. # # Ignores files that agree. Prints a ">" for files that exist on the second directory but # not the first, "<" for the oposite and "*" for files that differ. # # The purpose of this program is # Requirements require 5.004; use strict; use File::Find; use File::Compare; # Globals my $revision="1.1"; my $progname = "vario"; my $count = 1; my $diffs = 0; my $dir2missing = 0; # check args if ( $#ARGV < 1 ) { &usage; } # Check that directories exist my $dir1 = $ARGV[0]; my $dir2 = $ARGV[1]; opendir(DIR,"$dir1") or die "cannot open dir $dir1 - $!"; closedir(DIR); opendir(DIR,"$dir2") or die "cannot open dir $dir2 - $!"; closedir(DIR); # Find all files in directory 1 print "Processing $ARGV[0]...\n"; find(\&compare_files, $ARGV[0]); # Report my $time = localtime; print "\nvario ended at $time, $count total, $diffs diff(s) and $dir2missing file(s) missing from dir2.\n"; # Compare files sub compare_files () { my $file1 = $File::Find::name; -d and return; $count++; my $file2 = $file1; # Parse out dir2's file spec $file2 =~ s/$dir1/$dir2/; # Does file2 exist? if (! -e $file2 ) { $dir2missing++; print "< $file1\n" and return; } # Compare dir1 with dir2's file if (compare("$file1","$file2") == 1) { $diffs++; print "* $file1\n"; } } # Usage statement sub usage() { printf "vario: Compares two directories\n\n"; printf "usage: vario dir1 dir2\n"; exit 1; }