Technical Editor Bob Bowers showed me this tip and it really knocked my socks off. I couldn't believe you could delete a file from your local hard drive or a shared volume using a couple of script steps. It's easy if you already know how to specify a dynamic file path using a variable. For those of you who aren't familiar with the technique, I'll go over it briefly
In past issues, I've demonstrated how to save PDF files or export data from FileMaker Pro with a dynamic file name and path. All you have to do is declare a script variable with the path where you want to save the file and a file name. For example, the following script steps save a PDF file on your desktop with the name stored in the "myfile" field:
Set Variable [$Path; Value: "file:" & Get(DesktopPath) & MYTABLE::myfile & ".pdf"]
Save Records as PDF [Restore; No dialog; "$Path"; Records being browsed]
Instead of specifying the output file path with a static path, you can use a variable to declare a dynamic file path using calculations. There are half a dozen functions that locate paths on the local hard drive:
Get(DesktopPath)
Get(DocumentsPath)
Get(FilePath)
Get(PreferencesPath)
Get(FileMakerPath)
Get(TemporaryPath)
After you understand how to save a file dynamically, you can also delete it dynamically. Using the same Set Variable script step and the Export Field Contents script step, you can delete a file anywhere on your local hard drive or a shared volume:
Set Variable [$Path; Value: "file:" & Get(DesktopPath) & MYTABLE::myfile & ".pdf"]
Export Field Contents ["$Path"]
The key to this technique is not specifying a target field on the Export Field Contents script step. Only specify the path using the script variable and you'll delete the file, not just overwrite it.