Stripping just the filename

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
Greg,

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

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

Kerry Moorman
 
This is definitely superior than parsing the string to extract the filename,
which I have been doing to do things like this.

Cyril Gupta
 
Back
Top