有關檔案資訊的 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP