The problem that should be address before implementing more complex things is to clearly identify the backups.
In order to be certain to identify that the archives concern the document we are saving, I check
- For the FCBack extension:
- the presence of the base name + “.”,
- the length of what is in between that must the length of a date
- for the old fashion, I check
- the presence of the full name with extension,
- and the length of what follows that must be 1 or 2 (1 to 99)
These checks ensure that the file is not that main file of another project, and unless the user has changed the name of the archive, that it is an archive of this project.
I am able to manage both formats, and even if the format is changed during the life of the project, the n latest backups and only these backups will be kept.
Before we implement things more complex, we must define how we will identify the backups. It would be a real problem if we remove backups of a different project, and even worse the main file itself!
I will incorporate the format of the date as a start.
Here is the change: