檢查檔案是否在 C# 中隱藏


如需檢索檔案的屬性,請使用 FileAttributes 列舉型別。它具有壓縮、目錄、隱藏等各種成員。

如需檢查檔案是否隱藏,請使用隱藏成員名稱。

如果設定了 FileAttributes.hidden,將表示檔案處於隱藏狀態。首先,獲取路徑以查詢屬性。

FileAttributes attributes = File.GetAttributes(path);

如果設定了以下內容,將表示現在已使用隱藏成員名稱隱藏了檔案。

 File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
Console.WriteLine("The {0} file is hidden.", path);

更新於:30-7-2019

788 次檢視

開啟你 職業生涯

完成課程並獲得認證

開始
廣告