Just File Name

  • Thread starter Thread starter Altman
  • Start date Start date
A

Altman

OK I could write a little method to do this but I was wondering if it
already existed. I've searched but cannot find it.
I have a file string, example "C:\my documents\mydoc.doc"
I want to call a function that will return just the file name "mydoc.doc"
 
Altman said:
OK I could write a little method to do this but I was
wondering if it already existed. I've searched but cannot find it.
I have a file string, example "C:\my documents\mydoc.doc"
I want to call a function that will return just the file name
"mydoc.doc"

'System.IO.Path.GetFileName'
 
Take a look at the Name Property of The FileInfo class (System.IO.FileInfo)

Dim Info As New System.IO.FileInfo("C:\my documents\mydoc.doc")
Console.WriteLine(Info.Name)

hope that helps...
Imran.
 
Altman,
Have you tried System.IO.Path.GetFileName?

Something like:

Dim path As String = "C:\my documents\mydoc.doc"
Dim name As String
name = System.IO.Path.GetFileName(path)

System.IO.Path has a number of other useful functions for getting parts of a
path, plus functions to manipulate paths, such as Path.ChangeExtension &
Path.Combine.

Hope this helps
Jay
 
You'll be better off using the System.IO.Path.GetFileName as Herfried and
Jay suggested (unless you need more functionality that the FileInfo class
provides).

(I always seem to forget this class :-S)

Imran.
 
Well done.

I JUST finished writing a method that would do exactly that... of course I
wasn't smart enough to see if it already existed :-)

This would be funny if it weren't so embarrassing...
 
yeah I have done that many times. But I have learned my lesson and now I
always check before I make a method like that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top