VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A very efficient way to return a file name from a full path.

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.

Rate 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


Download this snippet    Add to My Saved Code

A very efficient way to return a file name from a full path. Comments

No comments have been posted about A very efficient way to return a file name from a full path.. Why not be the first to post a comment about A very efficient way to return a file name from a full path..

Post your comment

Subject:
Message:
0/1000 characters