Get filename without path

closet geek

Member
Joined
Apr 2, 2006
Messages
21
Hi,

I have a tabbed application, when a user opens a file to be displayed in a tab I naturally want the filename to appear in the tab.

Using this:

Code:
openFileDialog1.get_FileName()

Puts the whole path in the tab, making the tab very long e.g.

C:/path/to/file.txt

I just want:

file.txt

To be in the tab. How do I go about doing that?

Thanks.
 
closet geek said:
Hi,

I have a tabbed application, when a user opens a file to be displayed in a tab I naturally want the filename to appear in the tab.

Using this:

Code:
openFileDialog1.get_FileName()

Puts the whole path in the tab, making the tab very long e.g.

C:/path/to/file.txt

I just want:

file.txt

To be in the tab. How do I go about doing that?

Thanks.

Code:
dim stringBuffer() as String
stringBuffer = split("C:/path/to/file.txt", "/")

fileName = stringBuffer(ubound(stringBuffer))
 
Code:
dim path as string = "C:/path/to/file.txt"
System.IO.Path.GetFileName(path)
This way it will work regardless of whether the path uses "\"s or "/"s.
 
Old way...

Hi:

I to try to use the GetFileName methods like the other posters suggested...however, I sometimes do the following:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Path As String
Dim Pos As Integer

Path = "C:\FilePath\ReallyLong\LotsofDirectories\Practice\ScratchPad\bin\testing.bmp"
Pos = Path.LastIndexOf("\")
Path = Path.Substring(Pos + 1, Path.Length - (Pos + 1))

return file name
MsgBox(Path)

End Sub
 
Back
Top