Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Chương trình C# lấy thông tin file

FileInfo.Attributes trả về FileAttributes (enum flags) cho biết file là ReadOnly, Hidden, Archive, System, Directory, v.v.

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);
    }
}

Kết quả

Normal

Các giá trị thường gặp: Archive, Hidden, ReadOnly, System, Temporary. Kết hợp bằng bitwise OR.