File tokens apparently cannot be made for file names containing (some) special characters

Tried making a file-saving token for a file named “Image #1 copy.jpg”.

It stops at the following step:

const saveFile = await saveToFolderEntry.createFile(nameOfDocument, {overwrite: true});

where nameOfDocument = “Image #1 copy.jpg”

If I remove the “#” so that nameOfDocument = “Image 1 copy.jpg”, then it works.

Not sure yet what other special characters are affected, but the hashtag character appears to be problematic.

nameOfDocument = “Image-1 copy.jpg” appears to work. So a hyphen is acceptable.

Bit frustrating that these special characters cause problems like this. I use the hashtag character in my images all the time and assume at least some plugin users will use it too as well as other special characters.

Is it necessary to search through these document names and remove/replace special characters, or is there another solution? Also, is there a list of special characters to avoid?

There are some characters you should avoid, and I’d have sworn we had them documented. But I can’t find it. It is part of the error message that is thrown, but if it’s caught, then it can be hard to notice.

Avoid these characters: \/:*?"<>|#

My suggestion is to do a string replace here that replaces any instances of the above characters with a dash.