Remove last filename from end of path

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
In a rich text box I store the path of the file I want to move.

example:
C:\Documents and Settings\barker44\Desktop\DiabetesMonitor\Barker_Cita385FinalProject\DataBase\DiabetesMonitor.mdb

I need to use all of the path except the name of the data base. The path won't always be the same, but it will always end with \nameOfDataBase.mdb.

Any suggestions?
 
I'll give you a hint so you can figure this out yourself. Use string.substring() and string.lastindexof(). If you still have problems with it I'll give you some code.
 
I got told off for using the substring and indexof version :D - see this thread

VB.NET:
        Dim sFullFileName As String = "C:\Documents and Settings\barker44\Desktop\DiabetesMonitor\Barker_C ita385FinalProject\DataBase\DiabetesMonitor.mdb"

        MessageBox.Show(IO.Path.GetDirectoryName(sFullFileName))
 
The problem is can you figure it out, not here use this. I don't like giving the answer but for something like this it is better for him to figure out how to do it himself the manual way and then give the easy way.
 
I used a fileInfo object, from another forum, so I just had to do this

VB.NET:
 Dim f As New FileInfo(Me.rtbDataBaseSelected.Text)
 MessageBox.Show(f.FullName)
 Dim s As String = f.FullName.Replace(f.Name, "")
 MessageBox.Show(s)
 
Back
Top