Hi 

Thanks. I tried this script. It compares the filenames within the directory very well. 
But i want to compare even the contents and report the differences between the files. 

Regards
Sudhindra
  


On Tue, 22 Jun 2004 LRMK wrote :
>
>This must do the <A TITLE="Click for more information about job" 
>STYLE="text-decoration: none; border-bottom: medium solid green;" 
>HREF="http://search.targetwords.com/u.search?x=5977|1||||job|AA1VDw">job</A> but 
>there must be a more nice looking way of doing this
>
>
>Code
>___________________________________________________________
>
>compare("c:\\program files","d:\\program files");  #Example call
>
>
>sub compare($$){
>     my ($p1, $p2) [EMAIL PROTECTED];
>
>
>     print "comparing $p1 with $p2\n";
>
>     ################################v Loading direcrory 1
>     opendir(DIR1, $p1);
>     my @dirList1 = readdir(DIR1);
>     closedir(DIR1);
>
>     ################################v Loading direcrory 2
>     opendir(DIR2, $p2);
>     my @dirList2 = readdir(DIR2);
>     closedir(DIR2);
>
>     my %hash1;
>     my %hash2;
>     foreach my $item (@dirList1){
>         $hash1{$item} = 1;
>     }
>
>     foreach my $item (@dirList2){
>         $hash2{$item} = 1;
>     }
>
>
>     ################################ Counting the items that are in Path 1
>but not in path 2
>     my $c=0;
>     foreach my $key (sort keys %hash1){
>
>         if ($hash2{$key}!=1){
>             #print "$key\n";
>             $c++
>         }
>
>     }
>     print "Number of items that are in $p1 but not in $p2 - $c\n";
>
>     ################################ Counting the items that are in Path 2
>but not in path 1
>     $c=0;
>     foreach my $key (sort keys %hash2){
>
>         if ($hash1{$key}!=1){
>             #print "$key\n";
>             $c++;
>         }
>
>     }
>     print "Number of items that are in $p2 but not in $p1 - $c\n";
>
>print "_______________________\n";
>
>
>     ####################################################### Comparing Sub
>directories
>     foreach my $key (sort keys %hash1){
>         if
>(($hash2{$key}==1)&&(isSubDirectory($p1,$key))&&(isSubDirectory($p2,$key))){
>
>             compare($p1 . "\\" . $key, $p2 . "\\" . $key);
>
>         }
>     }
>}
>
>
>
>
>#################################### Sub to check whether an item is a valid
>sub directory of the given path
>sub isSubDirectory($$){
>     my ($path, $item)[EMAIL PROTECTED];
>     if ($item =~m/^(\.)+$/){
>         return 0;
>     }
>     my $myItem = $path. "\\" . $item;
>     if (-d $myItem){
>         return 1;
>     }else{
>         return 0;
>     }
>
>
>}
>
>
>
>LRMK
>----- Original Message -----
> From: "sudhindra k s" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Tuesday, June 22, 2004 1:24 PM
>Subject: Comparing Directories
>
>
>
>Hi
>
>I have two directories with a path as shown below
>c:\test\result\... and d:\test2\result2\...
>
>The directory stucture and files after these are the same. i.e if there is a
>directory xyz within c:\test\result\, there will be a corresponding
>directory xyz within d:\test2\result2\ with the file names also being the
>same.
>
>now i want to compare the contents of the directories and output the
>difference between the two if any. How can i acheive this?
>
>Regards
>Sudhindra
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


Reply via email to