다음을 통해 공유


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 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 하고 캐시합니다. 후속 호출에서 를 호출 Refresh 하여 정보의 최신 복사본을 가져와야 합니다.

파일 이름에는 파일 확장명을 포함합니다.

적용 대상

추가 정보