REBOL [
    Title: "Safe file name"
    Purpose: {Check a file name string for characters that might cause
    problems in certain situation.}
]

;; [---------------------------------------------------------------------------]
;; [ This is a function written for one purpose, to check a file name for      ]
;; [ characters that might cause problems with certain automated procedures.   ]
;; [ A file name that generally will NOT cause problems is one that contains   ]
;; [ only letters, numbers, hyphens, and underscores.  Not that other          ]
;; [ characters WILL cause problems, but they could, so this function just     ]
;; [ checks the file name to see if it MIGHT be a problem.                     ]
;; [===========================================================================]

SAFE-FILENAME: context [
    UPPER: charset [#"A" - #"Z"] 
    LOWER: charset [#"a" - #"z"] 
    DIGIT: charset [#"0" - #"9"]
    SPECIAL: charset "-_."
    OK-FILENAME: [some [UPPER | LOWER | DIGIT | SPECIAL]]
    CHECK: func [
        FILE-ID
    ] [
        return parse/all to-string FILE-ID OK-FILENAME
    ]
]

;;Uncomment to test
;TESTID: %TESTFILE.TXT
;print [TESTID ":" SAFE-FILENAME/CHECK TESTID]
;TESTID: "TEST FILE.TXT"
;print [TESTID ":" SAFE-FILENAME/CHECK TESTID]
;TESTID: to-local-file "TEST FILE (1).TXT"
;print [TESTID ":" SAFE-FILENAME/CHECK TESTID]
;halt