"It's as if FMP thinks there's already a file with that name in the directory, even though there's not."
After the first time you run the script, there is a file with that name. The temp folder doesn't clear out until you quit filemaker.
If you substitute the Documents folder for the temp folder do you get the same result?
This could well be OS level rather than FM level, where it automatically appends the number to avoid overwriting an existing file. FM clears the temporary directory when a session ends (I believe), so when you run it repeatedly within a single session you may need to clear FM's temporary directory before running the script. Not sure how to do this, but I'm sure there is a way.
Good idea. I have tried to find a way to somehow clear temporary directory but no luck. If I clear it manually it doesn't seem to make a difference. Perhaps even though it's empty in file explorer it's not really 'empty'?
That seems to have worked. Using Get(documentspath) instead of Get(TemporaryPath)
Ok, scratch that. Get(DocumentsPath) does display same behavior and also leaves exported doc behind in Docs folder.
I think I can find a workaround. It seems my system is creating multiple sessions in temp folder for some reason, i.e. S1, S12, S13 and this is causing the increment of exported contents.
I think that occurrs at storing container field it is configured as "external storage", not exporting. "Export filed contents" overwrite old file, or cause error if it can't be overwritten.
How about deleting container field (and commit) before set new contents?
It may be caused that FM should keep old contents for undoing or shared users before committed with new contents.
Unfortunately that does not appear to make a difference.
I think FM stores a reference to the externally stored document and if it determines document has been modified/moved or otherwise interfered with it assigns a new reference to a subsequently saved doc having the same name, then the suffix is appended to the externally saved file.
Only solution I see is to prevent users from doing anything to the saved external files.