Linux read only 檔案,FileAttributes

FileAttributes 列舉

定義

組件:mscorlib.dll, System.IO.FileSystem.Primitives.dll

組件:System.Runtime.dll

組件:mscorlib.dll, netstandard.dll

組件:System.IO.FileSystem.Primitives.dll

組件:mscorlib.dll

組件:netstandard.dll

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

此列舉有 FlagsAttribute 屬性,因此其成員值可進行位元組合。

本文內容

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

[]

type FileAttributes =

[]

[]

type FileAttributes =

[]

[]

[]

type FileAttributes =

Public Enum FileAttributes

欄位

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

2048

檔案已壓縮。The file is compressed.

Device

64

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

Directory

16

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

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

2

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

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

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 支援 Normal。Normal is supported on Windows, Linux, and macOS.

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

8192

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

Offline

4096

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

ReadOnly

1

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

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 支援 ReparsePoint。ReparsePoint is supported on Windows, Linux, and macOS.

SparseFile

512

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

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

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.

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.

適用於

另請參閱

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值