String manipulation - Need last part of directory!

Speckled

Member
Joined
Feb 12, 2008
Messages
12
Programming Experience
1-3
Hi all, I'm new. :)

I am hoping you can help and I can share what knowledge I have with the rest of you.

I have a string which is a directory to a file. This directory can change.

Say for example, the directory is "C:\something\something\test.mp3" I only want the value "test.mp3"

Directory = "C:\something\something\test.mp3"

Or Directory = "C:\something\something\something\something\test.mp3"

How would I get only the last part of the directory, 'test.mp3'?

I know I could use the RIGHT function but it will only work for this string, the directory is changable.

Thankyou,
Ricky
 
VB.NET:
        Dim TheFullNameWithDirectory As String = "C:\something\something\test.mp3"
        Dim TheFileName As String = TheFullNameWithDirectory.Substring(TheFullNameWithDirectory.LastIndexOf("\") + 1)
 
IO.Path.GetFileName() function exist for this purpose.
 
Back
Top