CONTEXT
A PHP-based wiki that I use generates backups of documents everytime they are edited. The backups are stored in a backup directory and are named like this -
Welcome.0001.qwiki
Welcome.0002.qwiki
FAQ.0001.qwiki
FAQ.002.qwiki
The first two files are backups of file named Welcome.qwiki that has the data to generate a specific wiki page. The 0001 and 0002 are automatically added when backups are made. The next time the 'Welcome' page gets edited, a new backup with 0003 in the filename will be generated. However, if Welcome.0001.qwiki had been manually deleted, then the new backup will have 0001 in the filename.
PROBLEM
I am modifying the Wiki engine's code and want to add the ability to delete backup files with options such as - delete all backup files, delete all backup files for a specific wiki page, delete all backup files except the latest three, etc.
The 'delete all' code is easy to write, but what should be the code for the other options?
For 'delete all except three latest backups,' one would need to sort the files:
1) by name (e.g., FAQ.0001.qwiki and FAQ.0002.qwiki are in one category and Welcome.0001.qwiki and Welcome.0002.qwiki are in another), and then
2) by file-creation date (note that FAQ.0002.qwiki may be older than FAQ.0001.qwiki)
If I can figure out the sorting issue, the rest of the code should be easy to write. If the original wiki engine code was written so that backups for each document were made in their own, specific sub-directory, this would not have been a problem.
Thank you!