Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the extension of a file

Status
Not open for further replies.

DougHomeOffice

Programmer
Oct 31, 2001
37
0
0
US
How do I get the extension of a file when I have the full name and path as a string

-Thanks
 
Have you tried Right(RTrim(<yourpath>),3)?
Also you could use InStr to look for &quot;.&quot;
JHall
 
Here is a function I got off the net somewhere....

Code:
Public Function GetFileExtension(strFileName As Variant) As String
    Dim strTemp As String
    Dim strTemp2 As String
    Dim intPos As Integer
    
    If IsNull(strFileName) Then
        strTemp = &quot; &quot;
    Else
        strTemp2 = strFileName
        intPos = InStrRev(strTemp2, &quot;.&quot;)
        If intPos = 0 Then
            strTemp = &quot; &quot;
        Else
            If intPos = Len(strTemp2) Then
                strTemp = &quot; &quot;
            Else
                strTemp = Mid(strTemp2, intPos + 1)
            End If
        End If
    End If
    
    GetFileExtension = strTemp
End Function

I think this will work with a full path.... I've not tested it that way... but it should.

GComyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top