1 Reply Latest reply on Mar 24, 2008 5:01 AM by [Jongware]

    [JS] File Naming Issues

    Level 1
      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
        • 1. Re: [JS] File Naming Issues
          [Jongware] Most Valuable Participant
          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).