You can do it in PHP. There's plenty of filesystem and directory tools chdir(), chmod(), etc ... You can find the whole list of them on php.net:
filesystem functions
directory functions
What you'd have to do is start at your base directory, then list everything it contains, check for the files you're interested in and directories, and then (assuming this is in a function) call the function recursively on all the directories.