Here's my take on it:
if [ $# -ne 1 ]; then
echo "Syntax $(basename $0) <FIND_BASE>"
if [ "$FIND_BASE" = "." ]; then
for d in $(find $FIND_BASE -type d -print); do
if [ "$d" != "$FIND_BASE" ]; then
ls $d | grep $SPECIAL_FILE &> /dev/null
if [ $? -ne 0 ]; then
echo "Deleting $d" | tee -a $LOGFILE
rm -rf $d 2>/dev/null
echo "Ignoring $d, contains $SPECIAL_FILE" | tee -a $LOGFILE
Add this to a script, modify the variables with your own naming convention if you like (for the special file and the log name), and then just call it with the starting directory path as a parameter. It will exclude any directory containing the file you want, and delete all the rest.