FileInfo.Name プロパティ

定義

ファイルの名前を取得します。Gets the name of the file.

public:
 virtual property System::String ^ Name { System::String ^ get(); };
public override string Name { get; }
member this.Name : string
Public Overrides ReadOnly Property Name As String

プロパティ値

String

ファイルの名前です。The name of the file.

次の例では、プロパティを使用して、 Name 現在のディレクトリにあるファイルの名前を表示します。The following example uses the Name property to display the names of files in the current directory.

using namespace System;
using namespace System::IO;
int main()
{
   
   // Create a reference to the current directory.
   DirectoryInfo^ di = gcnew DirectoryInfo( Environment::CurrentDirectory );
   
   // Create an array representing the files in the current directory.
   array<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.
   Collections::IEnumerator^ myEnum = fi->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      FileInfo^ fiTemp = safe_cast<FileInfo^>(myEnum->Current);
      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
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
Imports System.IO

Public Class NameTest
    Public Shared Sub Main()
        ' Create a reference to the current directory.
        Dim di As New DirectoryInfo(Environment.CurrentDirectory)
        ' Create an array representing the files in the current directory.
        Dim fi As FileInfo() = di.GetFiles()
        Console.WriteLine("The following files exist in the current directory:")
        ' Print out the names of the files in the current directory.
        Dim fiTemp As FileInfo
        For Each fiTemp In fi
            Console.WriteLine(fiTemp.Name)
        Next fiTemp
    End Sub
End Class
'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:
'newTemp.txt
'fileinfoname.exe
'fileinfoname.pdb
'fileinfoname.Resources.resources
'fileinfoname.vbproj.GenerateResource.Cache
'fileinfoname.xml

注釈

最初にを呼び出すと、はを FileInfo 呼び出し、 Refresh ファイルに関する情報をキャッシュします。When first called, FileInfo calls Refresh and caches information about the file. その後の呼び出しでは、 Refresh を呼び出して情報の最新のコピーを取得する必要があります。On subsequent calls, you must call Refresh to get the latest copy of the information.

ファイルの名前には、ファイル拡張子が含まれます。The name of the file includes the file extension.

適用対象

こちらもご覧ください