so I had this problem where I have to rename all files in a given folder to add timestamp at the start of the file name.
i.e. a.txt becomes 1324884311_a.txt
well your new files name pattern can be totally different, so this is just an indicator.
Also this is non recursive function and works on single folder only.
You may also be interested in looking at RecursiveDirectoryIterator class http://php.net/manual/en/class.recursivedirectoryiterator.php (requires PHP 5.3+)
Here is how I did it
First add this function to your Util class
Then I called this function on my directory like this
You can provide extra checks that can suit your need, or ask me If you have any specific need. the underlying logic to open a directory and reading all file names under it shall remain the same.
I am sort of not so active member on stackoverflow. But using the same technique I helped someone with similar problem
If you would like to have a look at my answer there you can browse to
I hope above helps