[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Help: regarding comparing two directory structures



Hi,
      I wish to compare tree stucures of two directories. that is to compare the subdirectories as well as their subdirectories and so on...only directories and subdirectories and their subdirectories. I am not interested about their contnets like files.
 
I am working on Solaris:
Here is the code which I prepared but it is not giving the appropriate results, Can any one help me in finding out the changes to eb made so that I can get the required output.
 
code is-----------------------
#! /bin/sh
#
#
#
#        function for comparing directories
#----------------------------function    compare()--------------------------------------------
compare(){
        echo "in compare function: "
        if [ -d $1 -a -d $2 ];
        then
                comparedir $1 $2
        else
                echo "type mismatch: $1 and $2"
                false
        fi
        return
  }
#
#-----------------------------Function comparedir()------------------------------------------
#
comparedir()
  {
        result=0
        echo "compare fdir function:"
        for i in `(ls -A $1 && ls -A $2)|sort|uniq`; do
                compare $1/$i $2/$i || result=1
        done
        return $result
   }
#
#
#--------------------------------Main script starts here---------------------------------------
bool=true
while($bool)
do
        echo "enter the standard directory with which comparision to be done: \c"
        read dir1
        if [ -d $dir1 ]; then
                bool=false
        else
                echo "$dir1 does not exists; enter valid directory name."
                bool=true
        fi
   if [ $bool = false ]; then
        echo "enter the directory to be compared: \c"
        read dir2
        if [ -d $dir2 ]; then
                bool=false
        else
                echo "$dir2 does not exists; enter valid directory name."
                bool=true
        fi
  fi
done
compare $dir1 $dir2
i=echo "$?"
if [ $i -eq 0 ];
then
        echo "directory tree structures are same!!!!!!!!!!!"
else
        echo "directory tree structures are not same????"
fi
exit 1
-------------------------------------------------
 
Thanks in advance
Rajesh



Yahoo! FareChase - Search multiple travel sites in one click.
Reply to: