Returns the file name of the specified path string without the extension.
[Visual Basic]
Public Shared Function GetFileNameWithoutExtension( _
ByVal path As String _
) As String
[C#]
public static string GetFileNameWithoutExtension(
string path
);
[C++]
public: static String* GetFileNameWithoutExtension(
String* path
);
[JScript]
public static function GetFileNameWithoutExtension(
path : String
) : String;
Parameters
- path
- The path of the file.
Return Value
A String containing the string returned by GetFileName, minus the last period (.) and all characters following it.
Exceptions
Remarks
This method does not verify that the path or file name exists.
For an example of using this method, see the Example section below. The following table lists examples of other typical or related I/O tasks.
Example
[Visual Basic, C#, C++] The following example demonstrates a use of the GetFileNameWithoutExtension method.
[Visual Basic]
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("GetFileNameWithoutExtension('{0}') returns '{1}'", pathname, result)
[C#]
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("GetFileNameWithoutExtension('{0}') returns '{1}'",
path, result);
[C++]
String * fileName = S"C:\\mydir\\myfile.ext";
String * path = S"C:\\mydir\\";
String * result;
result = Path::GetFileNameWithoutExtension(fileName);
Console::WriteLine(S"GetFileNameWithoutExtension('{0}') returns '{1}'",
fileName, result);
result = Path::GetFileName(path);
Console::WriteLine(S"GetFileNameWithoutExtension('{0}') returns '{1}'",
path, result);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
Path Class | Path Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File