Path.GetFileNameWithoutExtension Path.GetFileNameWithoutExtension Path.GetFileNameWithoutExtension Path.GetFileNameWithoutExtension Method

Definition

Overloads

GetFileNameWithoutExtension(ReadOnlySpan<Char>) GetFileNameWithoutExtension(ReadOnlySpan<Char>) GetFileNameWithoutExtension(ReadOnlySpan<Char>) GetFileNameWithoutExtension(ReadOnlySpan<Char>)
GetFileNameWithoutExtension(String) GetFileNameWithoutExtension(String) GetFileNameWithoutExtension(String) GetFileNameWithoutExtension(String)

Returns the file name of the specified path string without the extension.

GetFileNameWithoutExtension(ReadOnlySpan<Char>) GetFileNameWithoutExtension(ReadOnlySpan<Char>) GetFileNameWithoutExtension(ReadOnlySpan<Char>) GetFileNameWithoutExtension(ReadOnlySpan<Char>)

public:
 static ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path);
public static ReadOnlySpan<char> GetFileNameWithoutExtension (ReadOnlySpan<char> path);
static member GetFileNameWithoutExtension : ReadOnlySpan<char> -> ReadOnlySpan<char>
Public Shared Function GetFileNameWithoutExtension (path As ReadOnlySpan(Of Char)) As ReadOnlySpan(Of Char)

Parameters

Returns

GetFileNameWithoutExtension(String) GetFileNameWithoutExtension(String) GetFileNameWithoutExtension(String) GetFileNameWithoutExtension(String)

Returns the file name of the specified path string without the extension.

public:
 static System::String ^ GetFileNameWithoutExtension(System::String ^ path);
public static string GetFileNameWithoutExtension (string path);
static member GetFileNameWithoutExtension : string -> string
Public Shared Function GetFileNameWithoutExtension (path As String) As String

Parameters

path
String String String String

The path of the file.

Returns

The string returned by GetFileName(String), minus the last period (.) and all characters following it.

Exceptions

path contains one or more of the invalid characters defined in GetInvalidPathChars().

Examples

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

String^ fileName = "C:\\mydir\\myfile.ext";
String^ path = "C:\\mydir\\";
String^ result;
result = Path::GetFileNameWithoutExtension( fileName );
Console::WriteLine( "GetFileNameWithoutExtension('{0}') returns '{1}'", fileName, result );
result = Path::GetFileName( path );
Console::WriteLine( "GetFileName('{0}') returns '{1}'", path, result );

// This code produces output similar to the following:
//
// GetFileNameWithoutExtension('C:\mydir\myfile.ext') returns 'myfile'
// GetFileName('C:\mydir\') returns ''
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;

result = Path.GetFileNameWithoutExtension(fileName);
Console.WriteLine("GetFileNameWithoutExtension('{0}') returns '{1}'", 
    fileName, result);

result = Path.GetFileName(path);
Console.WriteLine("GetFileName('{0}') returns '{1}'", 
    path, result);

// This code produces output similar to the following:
//
// GetFileNameWithoutExtension('C:\mydir\myfile.ext') returns 'myfile'
// GetFileName('C:\mydir\') returns ''
Dim fileName As String = "C:\mydir\myfile.ext"
Dim pathname As String = "C:\mydir\"
Dim result As String

result = Path.GetFileNameWithoutExtension(fileName)
Console.WriteLine("GetFileNameWithoutExtension('{0}') returns '{1}'", fileName, result)

result = Path.GetFileName(pathname)
Console.WriteLine("GetFileName('{0}') returns '{1}'", pathname, result)

' This code produces output similar to the following:
'
' GetFileNameWithoutExtension('C:\mydir\myfile.ext') returns 'myfile'
' GetFileName('C:\mydir\') returns ''

Remarks

This method does not verify that the path or file name exists.

For a list of common I/O tasks, see Common I/O Tasks.

See Also

Applies to