Skip to main content
Known Participant
March 24, 2008
Question

[JS] File Naming Issues

  • March 24, 2008
  • 1 reply
  • 296 views
NOTE: I am writing JavaScript for InDesign CS2 and CS3.

My script involves writing file names that a user will input. The filenames will later be displayed in a menu. Since characters like ? % " / : can present problems, what's the best way to avoid bad file names? Should I just search the string for the characters I stated above before writing the filename? Or is there a better way to avoid bad characters?

If the best way is to scan for bad characters, what are all the characters I should prevent users from inputting? I thought of the following:
? % " / :

Are there any I missed?

Thanks in advance,
Dan
This topic has been closed for replies.

1 reply

Jongware
Community Expert
Community Expert
March 24, 2008
A slightly safer way is to scan for allowed characters! That way, you have ultimate control over everything a non-educated user could throw at you. Viz., you forgot the "/", which is (I think) allowed on a Mac, but not on Windows.

Test if the string consists only of characters in a string like "a..zA..Z0..9_-.!" (with the alphabet written out entirely; perhaps with a few more characters).