EvalFileName – Ensure that the basename of a file or directory is valid

EvalFileName – Ensure that the basename of a file or directory is valid

' 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 = TrueEnd Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes