> -----Original Message----- > From: zentara [mailto:[EMAIL PROTECTED]] > Sent: Thursday, July 25, 2002 12:18 PM > To: [EMAIL PROTECTED] > Subject: Re: directory scanning > > > On Thu, 25 Jul 2002 08:09:17 -0400, [EMAIL PROTECTED] (William > Black) wrote: > > >Hi All, > > > >I need an idea on how to approach a script. Say I had a > directory X with 50 > >files in it and I have another directory Y that is suppose > to have the same > >exact files in it as X. How could someone approach checking > directory Y > >aginst X to see if they had the same files? > > Here, this will get you most of the way there. > I'm stumped. To test this, I copied some files > from X to Y, but the md5_hex sums don't agree. > ????? > I checked the files with a hexdiff program and > they are identical. I wonder if Digest::MD5 can > be trusted???
It's fine. See below. > > ############################################ > #!/usr/bin/perl > use Digest::MD5 qw(md5_hex); > > $path= '/home/zentara/X/'; > $path1='/home/zentara/Y/'; > > opendir DIR, $path or die "can't ls $path: $!"; > @X= grep { $_ ne "." and $_ ne ".." } readdir DIR; > close DIR; > opendir DIR, $path1 or die "can't ls $path: $!"; > @Y= grep { $_ ne "." and $_ ne ".." } readdir DIR; > close DIR; > > #print "@X\n@Y\n"; > > foreach $file (@X){ > $file1= $path1.$file; > print "$file1\n"; > print md5_hex($file),"\n"; > print md5_hex($file1),"\n"; > > if ( md5_hex($file) ne md5_hex($file1)){ Uh, you're running the digest on the file *names* and not the file *contents*. Obviously, the file *names* aren't the same! > print "$file is not identical\n"} > } > > > %Z = map { $_ => 1 } @Y; > @diff = grep { not $Z{$_} } @X; > print "$path1 is missing @diff\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]