in reply to Directory comparison

good morning.

again, all the good things have been mostly said, so here is a snippet of code that will give you, after you supply two directories, the common files, the files unique to the first directory, the files unique to the second, and those that have been modified.

to determine modification we use industrial strength (gisle aas') MD5 rather than relying on file sizes, timestamps, etc. ie: we determine any differences in file content, rather than modification time. this works well with Ken Williams' Tie::Textdir, the other module used. the approach is good for source (and even binaries, i find), but you may want to look at times, in which case... go elsewhere!

use Tie::TextDir; use Digest::MD5; my ($dirA, $dirB) = @ARGV; tie my %filsA, 'Tie::TextDir', ($dirA || "."), 'rw'; tie my %filsB, 'Tie::TextDir', ($dirB || "."), 'rw'; my (%common, @uniqA, @uniqB, @modified); map { $common{$_} = Digest::MD5::md5_base64($filsA{$_}) if exists $filsB +{$_} } keys %filsA; map { push (@uniqA, $_) if ! exists $filsB{$_} } keys %filsA; map { push (@uniqB, $_) if ! exists $filsA{$_} } keys %filsB; @modified = grep { ! (Digest::MD5::md5_base64($filsB{$_}) eq $common{$_} ) } keys %common; untie %filsA; untie %filsB; print "** common to $dirA, $dirB **\n" . join "\n", keys %common; print "\n** unique to $dirA **\n" . join "\n", @uniqA; print "\n** unique to $dirB **\n" . join "\n", @uniqA; print "\n** modified files **\n" . join "\n", @modified; print "\n** finito **\n";
which produces output like

** common to chaffwin, chaffwin2 ** TO_DO md5.h README COPYING ChangeLog Makefile chaffwin.el chaffwin.o md5.o chaffwin.c chaffwin.pl md5.c CVS ** unique to chaffwin ** chaffwin.exe oot ** unique to chaffwin2 ** chaffwin.exe oot ** modified files ** chaffwin.o ** finito **


hope that helps

...wufnik

-- in the world of the mules there are no rules --