#!/usr/bin/perl

$mtApps= "/mt/apps/gpms";
$testMTApps = "/testmt/apps/gpms";
opendir TESTMTAPSS, "$testMTApps";
open DIFFILE,">>diff.txt";

foreach $subDir (readdir TESTMTAPSS){
print "\$subDir = $subDir\n";
$totalCounter=$totalCounter+$subcounter;
$subcounter=0;
#diff -rq /mt/apps/gpms/mrf2ea /testmt/apps/gpms/mrf2ea | cat >diff.txt
if ($subDir ne "." ){
if ($subDir ne ".." ){
$mtDir = $mtApps . "/" . $subDir;
$testMtDir = $testMTApps . "/" . $subDir;

#if (-d $mtDir){
#}else{
$subcounter++;
print DIFFILE "Comparing $mtDir and $testMtDir\n\n"; 
#print DIFFILE "$subcounter";
system "diff -brq $mtDir $testMtDir | cat >>diff.txt";
print DIFFILE "\n\n";
#};#if (-d $mtDir){

};
};
};

print DIFFILE "$totalCounter difference have been found between $mtDir and $testMtDir\n";
close DIFFILE;

open DIFFILEIN,  "<diff.txt";
open TESTMTONLY, ">>OnlyInTestMt.txt";
#Only in /testmt/apps/gpms
$numDiff=0;
while (<DIFFILEIN>){
$line =$_;

if ($line =~/Only in \/testmt\/apps\/gpms/){
if ($line =~/.xs/){
$numDiff++;
print TESTMTONLY "$numDiff $line";
};
};

};

print TESTMTONLY "There are $numDiff files in that appear only in $testMtDir\n";
close TESTMTONLY;
close DIFFILEIN;
$numDiff=0;
#Only in /mt/apps/gpms

open DIFFILEIN,  "<diff.txt";
open MTONLY,">>OnlyInMt.txt";


while (<DIFFILEIN>){
$line =$_;
#/mt/apps/gpms


if ($line =~/Only in \/mt\/apps\/gpms/){
if ($line =~/.xs/){
$numDiff++;
print MTONLY "$numDiff $line";
};
};

};

print MTONLY "There are $numDiff files in that appear only in $MtDir\n";
close MTONLY;
close DIFFILEIN;
$numDiff=0;

open DIFFILEIN,  "<diff.txt";
open DIFFOUT,">>difference.txt";


#differ

while (<DIFFILEIN>){
$line =$_;
#/mt/apps/gpms


if ($line =~/differ/){
$numDiff++;
print DIFFOUT "$numDiff $line";
};

};

print DIFFOUT "There are $numDiff differences between $MtDir and $testMtDir.\n";
#differ



