I’m probably late to this party, but since this just occurred to me…
There are times when you might need a file that goes away automatically. For example, you might set up a flag file that should be deleted when your app quits properly (if the file is there when the app starts up, you know that the app had crashed on a previous run, for example). Or perhaps you want to set up a temporary file that goes away when no longer needed.
The answer is a self-deleting FolderItem. Make a subclass of the FolderItem (SelfDeletingFolderItem), and then add a Destructor:
Protected Sub Destructor() if me.Exists then me.Delete end if End Sub
You can also add an Operator_Convert to make it easy to convert from an ordinary FolderItem:
Protected Sub Operator_Convert(f As FolderItem) me.Constructor( f ) End Sub
Now you can do things like:
dim f as SelfDeletingFolderItem = GetTemporaryFolderItem() myObj.TempFile = f // Create and use the TempFile
As soon as myObj goes out of scope, TempFile goes away by itself. (There is a design principle behind this whose name escapes me at the moment.) You can get fancier (and more dangerous), of course, and make sure that, if the FolderItem is actually a Directory, its contents get deleted too, but I’ll leave that as an exercise for the reader.
I hope this helps someone.