Determine Invalid Characters in File Name and Path

This is sample code. Add error handling and adjust to your requirements as necessary.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21

* Returns the list of characters that are not allowed in the file names
FUNCTION GetInvalidFileNameChars()
LOCAL lcInvalidFileNameChars, lnAsc
lcInvalidFileNameChars = [*/:<>?|\] + CHR(34)
FOR lnAsc=0 TO 31
	lcInvalidFileNameChars = lcInvalidFileNameChars + CHR(lnAsc)
ENDFOR
RETURN lcInvalidFileNameChars


* Returns the list of characters that are not allowed in the path names
FUNCTION GetInvalidPathChars()
LOCAL lcInvalidPathChars, lnAsc
lcInvalidPathChars = [*:<>?|] + CHR(34)
FOR lnAsc=0 TO 31
	lcInvalidPathChars = lcInvalidPathChars + CHR(lnAsc)
ENDFOR
RETURN lcInvalidPathChars

Comments

The less-than and greater-than symbols (CHR(60) and CHR(62)) are also considered invalid for both file and path names.