C# Path GetFileName
Description
Path GetFileName
Returns the file name and extension
of the specified path string.
Syntax
Path.GetFileName
has the following syntax.
public static string GetFileName(
string path
)
Parameters
Path.GetFileName
has the following parameters.
path
- The path string from which to obtain the file name and extension.
Returns
Path.GetFileName
method returns The characters after the last directory character in path. If the last character
of path is a directory or volume separator character, this method returns
String.Empty. If path is null, this method returns null.
Example
The following code example demonstrates the behavior of the GetFileName method.
using System.IO;/*from w w w . ja va2 s . c o m*/
using System;
public class MainClass
{
public static void Main(String[] argv)
{
string path = @"C:\mydir\";
string result;
result = Path.GetFileName(path);
Console.WriteLine("GetFileName('{0}') returns '{1}'",
path, result);
}
}
The code above generates the following result.