The System.IO.Path Class

Often you need to work with pathnames, directory names, and filenames. The .NET Framework provides the System.IO.Path class, offering shared members that allow manipulating pathnames. For example, you might want to extract the filename from a pathname. This is accomplished invoking the GetFileName method as follows:

'Returns "TextFile.txt" Dim fileName As String = Path.GetFileName("C:\TextFile.txt")

The GetExtension method returns instead only the file extension and is used as follows:

'Returns ".txt" Dim extension As String = Path.GetExtension("C:\TextFile.txt")

To ensure that a filename has an extension, you can also invoke the HasExtension method that returns True if the filename has one. There are situations in which ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.