Path: GetFileName |
Returns the file name and extension of the specified path string.
Public Function GetFileName( ByRef Path As String ) As String
The returned value is an empty string if the file path is an empty string.
The separator characters used to determine the start of the file name are DirectorySeparatorChar and AltDirectorySeparatorChar.
Exception | Condition |
---|---|
ArgumentException | Path contains one or more of the invalid characters defined in GetInvalidPathChars. |
The following code example demonstrates the behavior of the GetFileName method.
Public Sub Main() Const FileName As String = "C:\MyDir\MyFile.Ext" Const PathName As String = "C:\MyDir\" Dim Result As String Result = Path.GetFileName(FileName) Debug.Print CorString.Format("GetFileName('{0}') returns '{1}'", FileName, Result) Result = Path.GetFileName(PathName) Debug.Print CorString.Format("GetFileName('{0}') returns '{1}'", PathName, Result) End Sub ' This example code produces the following output. ' ' GetFileName('C:\MyDir\MyFile.Ext') returns 'MyFile.Ext' ' GetFileName('C:\MyDir\') returns ''