This function returns the file extension when passed the full filepath .
The function searches for the leading fullstop to determine to start of the file
extension. Add the following code to a FileHandling.bas standard module to compile a File
Utility function set:
Function GetExtName(ScanString as String) As String
'*******************************************************
'<DESC> Retrieves File Extension Name from full
' directory path</DESC>
'<RETURN> File Extension Only
' </RETURN>
'<ACCESS> Public
'<ARGS> FullPath:
' Full Filepath incl. Filename
' </ARGS>
'<USAGE> If GetExtName("c:\autoexec.bat")
' </USAGE>
'*******************************************************
Dim intPos as String
Dim intPosSave as String
If InStr(ScanString, ".") = 0 Then
GetExtName = ""
Exit Function
End If
intPos = 1
Do
intPos = InStr(intPos, ScanString, ".")
If intPos = 0 Then
Exit Do
Else
intPos = intPos + 1
intPosSave = intPos - 1
End If
Loop
GetExtName = Trim$(Mid$(ScanString, intPosSave + 1))
End Function
|