Path: HasExtension |
Determines whether a path includes a file name extension.
Public Function HasExtension( ByRef Path As String ) As Boolean
Starting from the end of Path, this method searches for a period (.) followed by at least one character. If this pattern is found before a DirectorySeparatorChar, AltDirectorySeparatorChar, or VolumeSeparatorChar character is encountered, this method returns True.
Exception | Condition |
---|---|
ArgumentException | Path contains one or more of the invalid characters defined in GetInvalidPathChars. |
The following code example demonstrates the use of the HasExtension method.
Public Sub Main() Const FileName1 As String = "MyFile.Ext" Const FileName2 As String = "MyDir\MyFile" Const AbsolutePath As String = "C:\MyDir.Ext\" Dim Result As Boolean Result = Path.HasExtension(FileName1) Debug.Print CorString.Format("HasExtension('{0}') returns {1}", FileName1, Result) Result = Path.HasExtension(FileName2) Debug.Print CorString.Format("HasExtension('{0}') returns {1}", FileName2, Result) Result = Path.HasExtension(AbsolutePath) Debug.Print CorString.Format("HasExtension('{0}') returns {1}", AbsolutePath, Result) End Sub ' This example code produces the following output. ' ' HasExtension('MyFile.Ext') returns True ' HasExtension('MyDir\MyFile') returns False ' HasExtension('C:\MyDir.Ext\') returns False