Recursively rename some files

Hello,

I have one directory with 3 level sub-directories, and about houndard files under those directories. I need a shell script to rename all patern mateched directories and files.

For example: the patern is AA in the directory or file name.

Orignal directory:
Dir1-->Dir_AA-->file_AA.txt
Dir1-->Dir_BB-->file1_AA.txt
Dir1-->Dir_CC-->Dir_BB-->file2_BB.txt

Target directory:
Dir1-->Dir_ZZ-->file_ZZ.txt
Dir1-->Dir_BB-->file1_ZZ.txt
Dir1-->Dir_CC-->Dir_BB-->file2_BB.txt

Thanks in advance,

Mike

find . -name '*AA*'  |
while read fname
do
    newname=$(echo "$fname" | sed 's/AA/ZZ')
    echo "moving $fname to $newname"
    # mv $fname $newname
done

Run it first with the # infront of mv - this prevents the mv command from actually being executed. Review the output. When you like it, remove the # character.

It does NOT work, since I have directories needs changing name as well.