Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools



Click here to copy the following block
' EvalFileName ensures that the basename of a file or directory
' conforms to the Microsoft file naming guidelines (see MSDN webpage)
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/
' naming_a_file.asp
'
' Return value:
'  True = Valid basename
'  False = Invalid basename
'
' Note: Since EvalFileName checks only the basename of a file or
' directory, it does not test the max filename length condition
' (ANSI 255 for files, 248 for directories, including the path)
' This error is however trapped by the APIMakeDirectory function
'
' Example:
'  MsgBox EvalFileName("test.txt")
'  MsgBox EvalFileName("inva:lid.txt")

Private Function EvalFileName(ByVal Name As String) As Boolean
              
  Dim i As Long
  Dim Test As String
  Const BAD_FILENAME_CHARS As String = """" & "/" & "\" & ":" & "|" & "<" & _
    ">" & "*" & "?"
  
  ' We need a name
  If Len(Trim$(Name)) = 0 Then
    Exit Function
  End If
  
  ' Test trailing space or period
  Test = Right$(Name, 1)
  If Test = " " Or Test = "." Then
    Exit Function
  End If
  
  ' Test illegal and non-printable characters
  Test = BAD_FILENAME_CHARS
  For i = 0 To 31
    Test = Test & Chr$(i)
  Next
  For i = 1 To Len(Name)
    If InStr(1, Test, Mid$(Name, i, 1)) > 0 Then
      Exit Function
    End If
  Next
  
  ' Test possible use of reserved words
  ' (CON, PRN, AUX, CLOCK$, NUL)
  If LCase$(Name) = "con" Or LCase$(Name) = "prn" Or LCase$(Name) = "aux" Or _
    LCase$(Name) = "clock$" Or LCase$(Name) = "nul" Then
      Exit Function
  End If
  ' COM/LPT (1-9)
  For i = 1 To 9
    If LCase$(Name) = "com" & CStr(i) Or LCase$(Name) = "lpt" & CStr(i) Then
      Exit Function
    End If
  Next
  
  ' All tests clear, return success
  EvalFileName = True

End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.