#!/bin/sh
# Delete all files in Animation* directories for a project in a given path.
# For a measure of safety, this is  
#
# ONLY USED AS A STAND-ALONE script, and
#
# the user needs to manually type in the path, then confirm the deletions.

# As with all ELM scripts, stay with Bourne shell (/bin/sh) for universal application.

get_yesno()
{
    ANS="X"
    while [ "$ANS" != "y" -a "$ANS" != "n" -a "$ANS" != "Y" -a "$ANS" != "N" ]
    do
      echo  " (y/n): "
      read ANS
    done
}

if test $# != 2
then
    echo "###### Error: you must supply 1) an existing OutputPath "
    echo "and 2) the model Project name. "
    echo "(example: rmAnim /myProjDirOutput/ myProj )"
    exit
fi

OutputPath=$1
ProjName=$2

# check that the full path for the model output exists
if test -d "$OutputPath/$ProjName/Output"
  then
  	clear
	echo ""
	echo "######"
	echo "###### CAUTION:  This script does what it says here:"
	echo "You will be DELETING **ALL** data in directories Animation1 - Animation60 located in:"
	echo "$OutputPath/$ProjName/Output/"
	echo "###### Is that ok? ###### (y/n)"
  else
    echo "###### Error: $OutputPath/$ProjName/Output "
    echo "does not exist on your network."
    echo "Check your path to the data you want deleted."
    exit
fi

get_yesno
if [ "$ANS" != "y" -a "$ANS" != "Y" ]
  then 
  exit
fi

####
#### Delete animation files (not directories)
dir=Animation
i=1
dirdata=0
fnum=0
########
########  hacked, inefficient - but does the job
while (test $i != 61)
do
  for fname in `ls $OutputPath/$ProjName/Output/$dir$i/ `
    do
    rm $OutputPath/$ProjName/Output/$dir$i/$fname
    fnum=`expr $fnum + 1`
  done
  if (test $fnum != 0)
    then
  	  echo "Deleted $fnum files in dir $OutputPath/$ProjName/Output/$dir$i/ "
      fnum=0
      dirdata=`expr $dirdata + 1`
    fi
  i=`expr $i + 1`
done
echo "Done with data deletions in $dirdata Animation directories in $OutputPath/$ProjName/Output/"



