Skip to content

Auto-Deleting Temporary Files

Did you know that you can make temporary FolderItems that automatically delete when they go out of scope? This technique makes it fairly easy. So let’s get to it.

  1. Add a class to your project and name it TempFolderItem.
  2. Add a Private property to the class named mFolderItem with a type of FolderItem.
  3. Add a Method to the class named Constructor.
  4. In the method, add the following code:
    mFolderItem = FolderItem.TemporaryFile()
  5. Add a Method to the class named Destructor.
  6. In the method, add the following code:
    mFolderItem.Delete
  7. Add a new Method to the class named Operator_Convert with a return type of FolderItem.
  8. In the method, add the following code:
    Return mFolderItem

That’s it! Now when you need a temporary file, create one of these objects like this:

Var myTempFile as New TempFolderItem

The Operator_Convert method makes it so you can use this object in any place where a FolderItem is expected and as soon as myTempFile goes out of scope, *POOF* the file disappears (assuming of course that no other process has locked the file).