FileInfo.Name Property
.NET Framework 4.5
Gets the name of the file.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
The following example uses the Name property to display the names of files in the current directory.
using System; using System.IO; public class NameTest { public static void Main() { // Create a reference to the current directory. DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory); // Create an array representing the files in the current directory. FileInfo[] fi = di.GetFiles(); Console.WriteLine("The following files exist in the current directory:"); // Print out the names of the files in the current directory. foreach (FileInfo fiTemp in fi) Console.WriteLine(fiTemp.Name); } } //This code produces output similar to the following; //results may vary based on the computer/file structure/etc.: // //The following files exist in the current directory: //fileinfoname.exe //fileinfoname.pdb //newTemp.txt
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.