Copy and paste the following code into your editor and run it (code comments are included).
You can add as many features as you wish from this piece of code.
If you want to see the live result (we believe this is the best way to learn what is the script about), try it here (new window).
The source code
This example browses a directory to list files and rename all files except the ones we do not want to list (as 'Thumbs.db' on windows or '..' and '.' which are not files as well as a directory itself).
Notes:
- we use the is_dir function to avoid renaming a directory;
- you need to have the necessary permissions to be able to write into a file on your server (see chmod on linux/unix).