FileAttributes 列舉

定義

提供檔案和目錄的屬性。

此列舉支援其成員值的位元組合。

public enum class FileAttributes
[System.Flags]
public enum FileAttributes
[System.Flags]
[System.Serializable]
public enum FileAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum FileAttributes
[<System.Flags>]
type FileAttributes = 
[<System.Flags>]
[<System.Serializable>]
type FileAttributes = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FileAttributes = 
Public Enum FileAttributes
繼承
FileAttributes
屬性

欄位

Archive 32

此檔案標示為包含在增量備份作業中。 Windows 會在每次修改檔案時設定這個屬性,而備份軟體應該在增量備份期間處理檔案時將其清除。

Compressed 2048

檔案已壓縮。

Device 64

保留供未來使用。

Directory 16

檔案是目錄。 Windows、Linux 及 macOS 支援 Directory

Encrypted 16384

檔案或目錄已加密。 對檔案而言,這表示檔案中的所有資料都被加密。 對於目錄而言,這表示加密 (Encryption) 是新建檔案和目錄的預設值。

Hidden 2

檔案是隱藏的,因此不會包括在一般目錄的清單內。 Windows、Linux 及 macOS 支援 Hidden

IntegrityStream 32768

包含資料完整性支援的檔案或目錄。 將這個值套用至檔案時,檔案中的所有資料流都有整合性支援。 將這個值套用至目錄時,該目錄中所有新的檔案和子目錄預設會包含完整性支援。

Normal 128

此檔案是沒有特殊屬性的標準檔案。 此屬性只有在單獨使用時有效。 Windows、Linux 及 macOS 支援 Normal

NoScrubData 131072

從資料完整性掃描中排除的檔案或目錄。 將這個值套用至目錄時,預設會從資料完整性中排除該目錄中所有新的檔案和子目錄。

NotContentIndexed 8192

作業系統的內容索引服務將不會編製檔案的索引。

Offline 4096

檔案為離線狀態。 檔案資料不是直接可供使用的。

ReadOnly 1

檔案是唯讀的。 Windows、Linux 及 macOS 支援 ReadOnly。 在 Linux 和 macOS 上,變更 ReadOnly 旗標是權限作業。

ReparsePoint 1024

檔案包含重新剖析的位置,它是與檔案或目錄有關聯的使用者定義的區塊。 Windows、Linux 及 macOS 支援 ReparsePoint

SparseFile 512

檔案是疏鬆檔案。 疏鬆檔案基本上為其資料幾乎包含零值的大型檔案。

System 4

檔案是系統檔案。 也就是說,檔案是作業系統的一部分,或由作業系統獨佔使用。

Temporary 256

檔案是暫存的。 暫存檔案,包含應用程式正在執行時所需的資料(但卻是應用程式完成後不需要的資料)。 檔案系統會嘗試將所有資料保留在記憶體中以便更快速存取,而不是將資料清除回大型存放區。 不再需要暫存檔案時,應用程式應盡快加以刪除。

範例

下列範例示範如何擷取檔案的屬性,並檢查檔案是否為唯讀。

using System;
using System.IO;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            FileAttributes attributes = File.GetAttributes("c:/Temp/testfile.txt");
            if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                Console.WriteLine("read-only file");
            }
            else
            {
                Console.WriteLine("not read-only file");
            }
        }
    }
}
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        Dim attributes = File.GetAttributes("c:/Temp/testfile.txt")
        If ((attributes And FileAttributes.ReadOnly) = FileAttributes.ReadOnly) Then
            Console.WriteLine("read-only file")
        Else
            Console.WriteLine("not read-only file")
        End If
    End Sub
End Module

備註

您可以藉由呼叫 File.GetAttributes 方法來取得檔案和目錄的屬性,也可以藉由呼叫 File.SetAttributes 方法來設定它們。

您無法使用 File.SetAttributes 方法來變更 物件的壓縮狀態 File 。 相反地,您必須使用壓縮工具或命名空間中的 System.IO.Compression 其中一個類別,實際壓縮檔案。

Linux 和 macOS 上的 .NET Core 不支援下列屬性:

在 Unix 系統上,針對名稱開頭為句號 (「的檔案,包含 HiddenFile.GetAttributes 傳回的值。) 。 在 macOS 上,您可以取得或設定隱藏旗標。

適用於

另請參閱