Visual Basic For Applications: Get filename from path

Platform:Visual Basic For Applications
Task:Get filename from path
Discussion:
You need to get just the filename out of a path. This example from http://snippets.dzone.com/posts/show/533
Example:
Function GetFilenameFromPath(ByVal strPath As String) As String
    ' Returns the rightmost characters of a string upto but not including the rightmost '\'
    ' e.g. 'c:\winnt\win.ini' returns 'win.ini'
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
        GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
    End If
End Function
Back to Index