Home All Groups Group Topic Archive Search About

Stripping just the filename

Author
24 May 2006 11:32 PM
Greg Larsen
I have a string that contains both the filename and the directory.  Something
like "c:\temp\test.txt".  I need a process that will take this string and
return only the file portion "text.txt".  How might I do this.  Kept in mind
sometimes the string may contain "C:/temp/test.txt".  Any ideas?

Author
24 May 2006 11:45 PM
Kerry Moorman
Greg,

You can use the System.IO.Path class. For example:

MsgBox(System.IO.Path.GetFileName("C:/temp/test.txt"))

Kerry Moorman


Show quoteHide quote
"Greg Larsen" wrote:

> I have a string that contains both the filename and the directory.  Something
> like "c:\temp\test.txt".  I need a process that will take this string and
> return only the file portion "text.txt".  How might I do this.  Kept in mind
> sometimes the string may contain "C:/temp/test.txt".  Any ideas?
Author
25 May 2006 8:02 AM
Cyril Gupta
This is definitely superior than parsing the string to extract the filename,
which I have been doing to do things like this.

Cyril Gupta