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 --
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.