by Ian Lent (6 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Thu 19th August 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)
A very efficient way to return a file name from a full path.
' Purpose: Convert a string from a fully qualified path to a file name.
' In: strPathName - The fully qualified path
' Out: None
' Date: 8/13/1999
' Programmer: Ian Lent
' Last Modified:
Dim lngIndex As Long ' Backslash character positon
Dim strRemnant As Variant ' What remains after trimming off
' everything to the left
' of the last backslash character.
strRemnant = strPathName
Do
lngIndex = InStr(strRemnant, "\")
If lngIndex = 0 Then Exit Do ' There are no more backslash characters: we have the name.
strRemnant = Right$(strRemnant, Len(strRemnant) - lngIndex)
Loop
FileNameOnly = strRemnant ' Sock it to me!
End Function