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

devx-admin

Share the Post: