Path: GetFileNameWithoutExtension

GetFileNameWithoutExtension

Returns the filename portion of a path without the filename extension.



 Public Function GetFileNameWithoutExtension(
	  ByRef Path As String ) As String

Parameters

Path
[ByRef] String. The path to parse the filename from.

Return Values

String -  A filename without the extension present.

Remarks

This function does not verify that the path or file exists.

Exceptions

ExceptionCondition
ArgumentException Path contains one or more of the invalid characters defined in GetInvalidPathChars.

Examples

The following code example demonstrates a use of the GetFileNameWithoutExtension method.

Public Sub Main()
    Const FileName As String = "C:\MyDir\MyFile.Ext"
    Const PathName As String = "C:\MyDir\"
    
    Dim Result As String
    
    Result = Path.GetFileNameWithoutExtension(FileName)
    Debug.Print CorString.Format("GetFileNameWithoutExtension('{0}') returns '{1}'", FileName, Result)
    
    Result = Path.GetFileNameWithoutExtension(PathName)
    Debug.Print CorString.Format("GetFileNameWithoutExtension('{0}') returns '{1}'", PathName, Result)
End Sub

' This example code produces the following output.
'
'    GetFileNameWithoutExtension('C:\MyDir\MyFile.Ext') returns 'MyFile'
'    GetFileNameWithoutExtension('C:\MyDir\') returns ''

See Also

Project CorLib Overview

Class Path Overview