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.
- Add a class to your project and name it TempFolderItem.
- Add a Private property to the class named mFolderItem with a type of FolderItem.
- Add a Method to the class named Constructor.
- In the method, add the following code:
mFolderItem = FolderItem.TemporaryFile()
- Add a Method to the class named Destructor.
- In the method, add the following code:
mFolderItem.Delete
- Add a new Method to the class named Operator_Convert with a return type of FolderItem.
- 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).