devxlogo

Easily Retrieve File Attributes

Easily Retrieve File Attributes

Sometimes, filenames may contain characters like “.” and file-extensions may not necessarily be always 3 characters long. This code provides a handy way to get file attributes in a foolproof way.

Function GetFileExtension (FileName As String) As String 'Filename can be with or without the absolute path. Dim sTemp() As String sTemp = Split(FileName, ".") GetFileExtension = sTemp(UBound(sTemp))End FunctionFunction GetFileName (FileName as String, _         Optional WithExtension As Boolean = True) As String 'Filename can be with or without the absolute path. Dim sTemp() As String sTemp = Split(FileName, "") GetFileName = sTemp(UBound(sTemp))        'FileName with Extension If Not WithExtension Then    sTemp = Split(GetFileName, ".")    Redim Preserve sTemp(UBound(Stemp-1))  'FileName without extension    GetFileName = Join(sTemp, ".") End IfEnd FunctionFunction GetFilePath (FileName as String) As String Dim sTemp() As String sTemp = Split(FileName, "") Redim Preserve sTemp(UBound(Stemp-1))  GetFilePath = Join(sTemp, "")End Function
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist