Python script to recursively change directory permissions

This is similar to using the Unix find command to recursively set directory permissions. Often you want to do this to make sure that permissions on all directories under a given path are set to a specific value.

find /var/www/html -type d -exec chmod 750 {} \;

Today I decided I wanted to do it in Python. I created the following interactive script which takes two arguments: the path and the permission mode. For example it can be run like:

chmoddirs /var/www/html 750

If the user enters invalid data it will print a message and quit. If the data is valid then it asks for a confirmation before executing.