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:
? % " / :
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).