FileInfo.Name プロパティ

定義

ファイルの名前を取得します。

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

プロパティ値

ファイルの名前。

次の例では、 Name プロパティを使用して、現在のディレクトリ内のファイルの名前を表示します。

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

注釈

最初に呼び出されると、 FileInfoRefresh を呼び出し、ファイルに関する情報をキャッシュします。 後続の呼び出しでは、 Refresh を呼び出して、情報の最新のコピーを取得する必要があります。

ファイルの名前には、ファイル拡張子が含まれます。

適用対象

こちらもご覧ください