Doing the Delete

The user has to run the TimeDelete application directly, i.e. not from the SendTo menu, to scan the list of files and delete any that have expired. The first thing we need is the path to the data file and this is a matter of reading the Shortcut again to obtain the target path:

Now that we have the path we can open the data file. This time we have no choice but to use a more standard approach to file handling and use a Streamreader – but the File object still provides an easy way to get one:

We have to close the stream explicitly in this case. Also notice the use of the Join method to rebuild the line from the separate elements in the string array. When the do loop comes to and end all of the lines of the file have been processed, the files have either been deleted or not according to what the user selected, and all of the data lines corresponding to files that are still in date have been written to the new file.

The final task is to juggle the file names around so that the new file replaces the original. There are lots of ways of doing this but what you have to keep in mind that you don’t want to arrive at a state where there isn’t a backup file on the disc so one way of doing it is:

That is, first delete any existing file ending .$$$, then rename the .TDD file to .$$$ to create a new backup, and finally rename the temporary .T$$ file to .TDD. In this way the user has a backup of the list in the .$$$ file and during the swap over there is always one copy of the data left on the disk. You can try to work out what is the worst state the system can be left in if the process crashes before completion but to do the job better takes a lot of effort.