FileAttributes FileAttributes FileAttributes FileAttributes Enum

定義

提供檔案和目錄的屬性。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. 對於目錄而言,這表示加密是新建立的檔案和目錄的預設值。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.

適用於

另請參閱