Link to home
Start Free TrialLog in
Avatar of macros14
macros14

asked on

EASY STRING Q???????????

I have a string array that holds file paths but is nothing more then a file path with a file at the end of it.

\xx\yy\zz\aa.txt

How can I get the name of the text file so everything to the right of the last "\"???  When the file path to the file could be longer or shorter??  
ASKER CERTIFIED SOLUTION
Avatar of S-Twilley
S-Twilley

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
Avatar of S-Twilley
S-Twilley

Alternatively...

'as above, strPath contains the full filename

dim i as integer = strPath.LastIndexOf("\")
Dim filename as string = ""

If i >= 0 Then
    filename = strPath.Substring(i+1)
Else
    filename = strPath
End if

msgbox(filename)
Avatar of Mike Tomlinson
Another possibility:

Dim fullPathFileName As String = "C:\mydir\myfile.ext"
Dim fileName As String = System.IO.Path.GetFileName(fullPathFileName)
MsgBox(fileName)