Path: GetExtension |
Returns the extension of the specified path string.
Public Function GetExtension( ByRef Path As String ) As String
The extension of Path is obtained by searching path for a period (.), starting with the last character in Path and continuing toward the start of Path. If a period is found before a DirectorySeparatorChar or AltDirectorySeparatorChar character, the returned string contains the period and the characters after it; otherwise, empty string is returned.
Exception | Condition |
---|---|
ArgumentException | Path contains one or more of the invalid characters defined in GetInvalidPathChars. |
The following code example demonstrates using the GetExtension method.
Public Sub Main() Const FileName As String = "C:\MyDir.Old\MyFile.Ext" Const PathName As String = "C:\MyDir.Old\" Dim Extension As String Extension = Path.GetExtension(FileName) Debug.Print CorString.Format("GetExtension('{0}') return '{1}'", FileName, Extension) Extension = Path.GetExtension(PathName) Debug.Print CorString.Format("GetExtension('{0}') return '{1}'", PathName, Extension) End Sub ' This example code produces the following output. ' ' GetExtension('C:\MyDir.Old\MyFile.Ext') returns '.Ext' ' GetExtension('C:\MyDir.Old\') returns ''