C# Path GetFileNameWithoutExtension

Description

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

Syntax

Path.GetFileNameWithoutExtension has the following syntax.


public static string GetFileNameWithoutExtension(
  string path
)

Parameters

Path.GetFileNameWithoutExtension has the following parameters.

  • path - The path of the file.

Returns

Path.GetFileNameWithoutExtension method returns The string returned by GetFileName, minus the last period (.) and all characters following it.

Example

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


// ww w . j  a v  a2 s .c o  m
using System;
using System.IO;
public class MainClass{
  public static void Main(String[] argv){  
    string fileName = @"C:\mydir\myfile.ext";
    string path = @"C:\mydir\";
    string result;
    
    result = Path.GetFileNameWithoutExtension(fileName);
    Console.WriteLine(result);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter