#!/bin/bash

# ----------------------------------------------------------------------
# blabla
# ----------------------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`

# on eclate les variables pouvant contenir un blanc
if test $# -gt 0
   then set $*
fi

if (test $# = 1 ) 
   then
     if (test $1 = -h )
        then echo "$appli : Give directories for all the tree"
             echo "Usage: $appli"
             echo "Usage: $appli dir"
             exit 0
     fi
fi

nomdir=.

if test $# = 1
   then
   nomdir=$1
fi



gene=`date +%Y%m%d'_'%H%M%S`

echo
echo "---------------------------------"
echo "Directories tree"
echo "---------------------------------"
echo

if test -d $nomdir
   then
      echo "Starting point:  $nomdir"
   else
      echo "*** Directory $nomdir does not exist"
      echo "*** $appli aborted !"
      exit 2
fi

echo "Please wait ..."

# remplissage du fichier des infos pour l'executable

if test -f dir_tree.tmp
   then rm dir_tree.tmp
fi
datimc=`date +%F'  '%H':'%M':'%S `
echo $datimc  >dir_tree.tmp
uname -n     >>dir_tree.tmp
uname -sr    >>dir_tree.tmp
echo $nomdir >>dir_tree.tmp
find $nomdir -type d -print |wc -l >>dir_tree.tmp
find $nomdir -type d -print         >toto_$$.tmp
sort toto_$$.tmp >>dir_tree.tmp
rm toto_$$.tmp

# exploitation du fichier et creation du fichier resultat

if test -f dir_tree.txt
   then rm dir_tree.txt
fi

# remove RPC_ from RPC command

appli=`echo $appli | cut -c5-`

# run appli.exe 

echo "Run $appli ..."
$RPC_DIR/bin/$appli.exe       > dir_tree.txt


rm dir_tree.tmp

cat dir_tree.txt
echo
echo ----------------------------------------
echo copy of results are in dir_tree.txt
echo ----------------------------------------
