FileAttributes FileAttributes FileAttributes FileAttributes Enum

定義

提供檔案和目錄的屬性 (Attribute)。Provides attributes for files and directories.

此列舉具有 FlagsAttribute 個屬性允許以位元方式合併其成員值。

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

欄位

Archive Archive Archive Archive 32

此檔案標示為包含在增量備份作業中。This file is marked to be included in incremental backup operation. Windows 會在每次修改檔案時設定這個屬性,而備份軟體應該在增量備份期間處理檔案時將其清除。Windows sets this attribute whenever the file is modified, and backup software should clear it when processing the file during incremental backup.

Compressed Compressed Compressed Compressed 2048

檔案已壓縮。The file is compressed.

Device Device Device Device 64

保留供未來使用。Reserved for future use.

Directory Directory Directory Directory 16

檔案是目錄。The file is a directory. Windows、Linux 及 macOS 支援 DirectoryDirectory is supported on Windows, Linux, and macOS.

Encrypted Encrypted Encrypted Encrypted 16384

檔案或目錄已加密。The file or directory is encrypted. 對檔案而言,這表示檔案中的所有資料都被加密。For a file, this means that all data in the file is encrypted. 對於目錄而言,這表示加密 (Encryption) 是新建檔案和目錄的預設值。For a directory, this means that encryption is the default for newly created files and directories.

Hidden Hidden Hidden Hidden 2

檔案是隱藏的,因此不會包括在一般目錄的清單內。The file is hidden, and thus is not included in an ordinary directory listing. Windows、Linux 及 macOS 支援 HiddenHidden is supported on Windows, Linux, and macOS.

IntegrityStream IntegrityStream IntegrityStream IntegrityStream 32768

包含資料完整性支援的檔案或目錄。The file or directory includes data integrity support. 將這個值套用至檔案時,檔案中的所有資料流都有整合性支援。When this value is applied to a file, all data streams in the file have integrity support. 將這個值套用至目錄時,該目錄中所有新的檔案和子目錄預設會包含完整性支援。When this value is applied to a directory, all new files and subdirectories within that directory, by default, include integrity support.

Normal Normal Normal Normal 128

此檔案是沒有特殊屬性的標準檔案。The file is a standard file that has no special attributes. 此屬性只有在單獨使用時有效。This attribute is valid only if it is used alone. Windows、Linux 及 macOS 支援 NormalNormal is supported on Windows, Linux, and macOS.

NoScrubData NoScrubData NoScrubData NoScrubData 131072

從資料完整性掃描中排除的檔案或目錄。The file or directory is excluded from the data integrity scan. 將這個值套用至目錄時,預設會從資料完整性中排除該目錄中所有新的檔案和子目錄。When this value is applied to a directory, by default, all new files and subdirectories within that directory are excluded from data integrity.

NotContentIndexed NotContentIndexed NotContentIndexed NotContentIndexed 8192

作業系統的內容索引服務將不會編製檔案的索引。The file will not be indexed by the operating system's content indexing service.

Offline Offline Offline Offline 4096

檔案為離線狀態。The file is offline. 檔案資料不是直接可供使用的。The data of the file is not immediately available.

ReadOnly ReadOnly ReadOnly ReadOnly 1

檔案是唯讀的。The file is read-only. Windows、Linux 及 macOS 支援 ReadOnlyReadOnly is supported on Windows, Linux, and macOS. 在 Linux 和 macOS 上,變更 ReadOnly 旗標是權限作業。On Linux and macOS, changing the ReadOnly flag is a permissions operation.

ReparsePoint ReparsePoint ReparsePoint ReparsePoint 1024

檔案包含重新剖析的位置,它是與檔案或目錄有關聯的使用者定義的區塊。The file contains a reparse point, which is a block of user-defined data associated with a file or a directory. Windows、Linux 及 macOS 支援 ReparsePointReparsePoint is supported on Windows, Linux, and macOS.

SparseFile SparseFile SparseFile SparseFile 512

檔案是疏鬆檔案。The file is a sparse file. 疏鬆檔案基本上為其資料幾乎包含零值的大型檔案。Sparse files are typically large files whose data consists of mostly zeros.

System System System System 4

檔案是系統檔案。The file is a system file. 也就是說,檔案是作業系統的一部分,或由作業系統獨佔使用。That is, the file is part of the operating system or is used exclusively by the operating system.

Temporary Temporary Temporary Temporary 256

檔案是暫存的。The file is temporary. 暫存檔案,包含應用程式正在執行時所需的資料(但卻是應用程式完成後不需要的資料)。A temporary file contains data that is needed while an application is executing but is not needed after the application is finished. 檔案系統會嘗試將所有資料保留在記憶體中以便更快速存取,而不是將資料清除回大型存放區。File systems try to keep all the data in memory for quicker access rather than flushing the data back to mass storage. 不再需要暫存檔案時,應用程式應盡快加以刪除。A temporary file should be deleted by the application as soon as it is no longer needed.

範例

下列範例顯示如何抓取檔案的屬性, 並檢查檔案是否為唯讀。The following example shows how to retrieve the attributes for a file and check if the file is read-only.

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呼叫方法來設定它們。You can get attributes for files and directories by calling the File.GetAttributes method, and you can set them by calling the File.SetAttributes method.

不可能File File.SetAttributes使用方法來變更物件的壓縮狀態。It is not possible to change the compression status of a File object by using the File.SetAttributes method. 相反地, 您必須使用壓縮工具或System.IO.Compression命名空間中的其中一個類別, 實際壓縮檔案。Instead, you must actually compress the file using either a compression tool or one of the classes in the System.IO.Compression namespace.

Linux 和 macOS 上的 .NET Core 不支援下列屬性:The following attributes are not supported by .NET Core on Linux and macOS:

在 Unix 系統上, 所傳回File.GetAttributes的值會包含Hidden名稱開頭為句號 (".") 的檔案。On Unix systems, the value returned by File.GetAttributes includes Hidden for a file whose name begins with a period ("."). 在 macOS 上, 您可以取得或設定隱藏旗標。On macOS, you can get or set the hidden flag.

適用於

另請參閱