파일에 대한 정보를 얻는다는 것은 해당 특정 파일에 대해 설정된 모든 속성을 얻는 것을 의미합니다. 예를 들어 파일은 일반, 숨김, 보관 등일 수 있습니다.
먼저 FileInfo 클래스를 사용하십시오 -
FileInfo info = new FileInfo("hello.txt"); 이제 FileAttributes를 사용하여 파일에 대한 정보를 얻으십시오 -
FileAttributes attr = info.Attributes;
다음은 코드입니다 -
예시
using System.IO;
using System;
public class Program {
public static void Main() {
using (StreamWriter sw = new StreamWriter("hello.txt")) {
sw.WriteLine("This is demo text!");
}
FileInfo info = new FileInfo("hello.txt");
FileAttributes attr = info.Attributes;
Console.WriteLine(attr);
}
} 출력
Normal