Sometime ago I wrote a simple script to run over a directory tree recursively.
Here it is. I think you can adapt it to your problem easily.
Code:
#!/bin/bash
recursewalk(){
for file in *
do if [ -d $file ]
then echo "Descending into $file"
cd $file
recursewalk
cd ..
fi
done
}
recursewalk