Make your own free website on Tripod.com

Strip File Extension From Full Path

'This function will check also if the given path is only directory.
'Insert the following code to your form:

Function GetExtension(FileName As String)

    Dim PthPos, ExtPos As Integer
   
    For i = Len(FileName) To 1 Step -1
        If Mid(FileName, i, 1) = "." Then
            ExtPos = i
            For j = Len(FileName) To 1 Step -1
                If Mid(FileName, j, 1) = "\" Then
                    PthPos = j
                    Exit For
                End If
            Next j
            Exit For
        End If
    Next i
   
    If PthPos > ExtPos Then
        Exit Function
    Else
        If ExtPos = 0 Then Exit Function
        GetExtension = Mid(FileName, ExtPos + 1, Len(FileName) - ExtPos)
    End If
End Function

Private Sub Form_Load()
    'Enter here the file you want to get its extension
    MsgBox GetExtension("c:\mydir\myfile.exe")
End Sub

Go Back