FileInfo.Name Property
Assembly: mscorlib (in mscorlib.dll)
The following table lists examples of other typical or related I/O tasks.
| To do this... | See the example in this topic... |
|---|---|
| Create a text file. | |
| Write to a text file. | |
| Read from a text file. | |
| Append text to a file. | |
| Retrieve a file extension. | |
| Retrieve the fully qualified path of a file. | |
| Retrieve the file name and extension from a path. | |
| Change the extension of a file. | |
| Retrieve only the directory name from a path. |
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); } }
import System.*;
import System.IO.*;
public class NameTest
{
public static void main(String[] args)
{
// Create a reference to the current directory.
DirectoryInfo di = new DirectoryInfo(Environment.
get_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.
for (int iCtr = 0; iCtr < fi.length; iCtr++) {
FileInfo fiTemp = fi[iCtr];
Console.WriteLine(fiTemp.get_Name());
}
} //main
} //NameTest
import System; import System.IO; public class NameTest { public static function Main() : void { // Create a reference to the current directory. var di : DirectoryInfo = new DirectoryInfo(Environment.CurrentDirectory); // Create an array representing the files in the current directory. var fi : FileInfo[] = di.GetFiles(); Console.WriteLine("The following files exist in the current directory:"); // Print out the names of the files in the current directory. for (var i : int in fi) Console.WriteLine(fi[i]); } } NameTest.Main();
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.