Skip to content

Get the file name from a full path string


Function FileNameFromPath(strFullPath As String) As String
    Dim I As Integer

    For I = Len(strFullPath) To 1 Step -1
        If Mid(strFullPath, I, 1) = "\" Then
            FileNameFromPath = Right(strFullPath, Len(strFullPath) - I)
            Exit For
        End If
    Next
End Function

This function gets just the file name from a string containg the full path to a file, as for instance found in a connect string.

4
Your rating: None Average: 4 (1 vote)

Comments

FileNameFromPath function

April 2, 2010 by Anonymous, 17 weeks 21 hours ago
Comment id: 7

What advantage does the function offer over Dir(strFullPath)?

Dir(strFullPath) only returns

May 21, 2010 by Anonymous, 10 weeks 1 day ago
Comment id: 9

Dir(strFullPath) only returns the file name if it actually exists on the local drive. The FileNameFromPath function does not check for existance and can therefore be used to for instance get a file name out of a connect string, without a file with that name existing locally.

AdaptiveThemes