Để nhận thông tin về một tệp có nghĩa là nhận được tất cả các thuộc tính được đặt cho tệp cụ thể đó. Ví dụ:một tệp có thể là bình thường, ẩn, lưu trữ, v.v.
Đầu tiên, hãy sử dụng lớp FileInfo -
FileInfo info = new FileInfo("hello.txt"); Bây giờ, hãy sử dụng FileAttributes để nhận thông tin về tệp -
FileAttributes attr = info.Attributes;
Sau đây là mã -
Ví dụ
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);
}
} Đầu ra
Normal