Link to home
Start Free TrialLog in
Avatar of 8831
8831

asked on

Get the name of a file of a string containing the full path name

I have the full path name in a string variable, eg.:
strFileName = "C:\temp\filename.txt"

How do I extract only the filename from the string above, in this case that would be "filename" only?
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

   Dim strFullPathToFileName As String
    Dim strPath As String
    Dim strFileName As String
    Dim backslashPos As Integer
   
    strFullPathToFileName = "C:\temp\filename.txt"
    backslashPos = InStrRev(strFullPathToFileName, "\")
    If backslashPos > 0 Then
        strPath = Left(strFullPathToFileName, backslashPos)
        strFileName = Mid(strFullPathToFileName, backslashPos + 1)
    Else
        strPath = ""
        strFileName = strFullPathToFileName
    End If
   
    Debug.Print strPath
    Debug.Print strFileName

Regards,

Idle_Mind
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial