Gustav Brock
Gustav at cactus.dk
Wed Jan 5 11:29:01 CST 2005
Hi Jim
We have a function that just replaces any invalid char with a valid
char:
Function TrimFileName( _
ByVal strFileName As String) _
As String
' Replaces characters in strFileName that are
' not allowed by Windows as a file name.
' Truncates length of strFileName to clngFileNameLen.
'
' 2000-12-07. Gustav Brock, Cactus Data ApS, Copenhagen
' 2002-05-22. Replaced string concatenating with Mid().
' No special error handling.
On Error Resume Next
' String containing all not allowed characters.
Const cstrInValidChars As String = "\/:*?""<>|"
' Replace character for not allowed characters.
Const cstrReplaceChar As String * 1 = "-"
' Maximum length of a file name.
Const clngFileNameLen As Long = 255
Dim lngLen As Long
Dim lngPos As Long
Dim strChar As String
Dim strTrim As String
' Strip leading and trailing spaces.
strTrim = Left(Trim(strFileName), clngFileNameLen)
lngLen = Len(strTrim)
For lngPos = 1 To lngLen Step 1
strChar = Mid(strTrim, lngPos, 1)
If InStr(cstrInValidChars, strChar) > 0 Then
Mid(strTrim, lngPos) = cstrReplaceChar
End If
Next
TrimFileName = strTrim
End Function
/gustav
>>> Jim.Hale at FleetPride.com 05-01-2005 17:18:16 >>>
Anybody know of a similar function that could be used to validate file
names? I let users add short descriptions to file names before they
are
saved and I badly need a function to validate their input.