Splitting filenames into parts

  • Thread starter Thread starter Dave Cullen
  • Start date Start date
D

Dave Cullen

The OpenFileDialog returns a full pathspec and file name in its Filename
property. I want to display only the file and extension without the
path. Is there a .NET function to extract that part of the string?

Thanks
 
Dave Cullen said:
The OpenFileDialog returns a full pathspec and file name in its Filename
property. I want to display only the file and extension without the
path. Is there a .NET function to extract that part of the string?

Thanks

io.Path.GetFileName(path)
 
Dave said:
The OpenFileDialog returns a full pathspec and file name in its Filename
property. I want to display only the file and extension without the
path. Is there a .NET function to extract that part of the string?

Thanks

If you need to get anything other than filename, check out the FileInfo
Class.
 
Suppose the filefullpath returned by the OpenFileDialog is stored in
strMyFile, then you can use FileInfo class to get all sort of information you
want.
Dim fInfo = New FileInfo(strMyFile)
Dim fName As String = fInfo.Name
Dim fExt As String = fInfo.Extension
Dim size As Long = fInfo.Length
bla...
bla...
bla....
Hope this answers your question.
VHD50.
 
Dave Cullen said:
The OpenFileDialog returns a full pathspec and file name in its Filename
property. I want to display only the file and extension without the
path. Is there a .NET function to extract that part of the string?

You may want to take a look at the shared methods of the 'System.IO.Path'
class.
 
Back
Top