有關檔案資訊的 C# 程式


瞭解檔案的資訊是指獲取為特定檔案設定的所有屬性。舉例來說,檔案可以是普通、隱藏、存檔等。

首先,使用 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

更新於: 2020 年 6 月 22 日

149 次瀏覽

開啟您的職業生涯

完成課程以獲得認證

開始
廣告