การรับข้อมูลเกี่ยวกับไฟล์หมายถึงการได้รับสิ่งที่ตั้งค่าแอตทริบิวต์ทั้งหมดสำหรับไฟล์นั้น ๆ ตัวอย่างเช่น ไฟล์อาจเป็นไฟล์ปกติ ซ่อน เก็บถาวร ฯลฯ
ขั้นแรก ใช้คลาส 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