FileSystem.SetAttr(String, FileAttribute) 方法

定義

設定檔案的屬性 (Attribute) 資訊。 相較於 SetAttrMy 功能可提升檔案 I/O 作業的產能和效能。 如需詳細資訊,請參閱FileSystem

public:
 static void SetAttr(System::String ^ PathName, Microsoft::VisualBasic::FileAttribute Attributes);
public static void SetAttr (string PathName, Microsoft.VisualBasic.FileAttribute Attributes);
static member SetAttr : string * Microsoft.VisualBasic.FileAttribute -> unit
Public Sub SetAttr (PathName As String, Attributes As FileAttribute)

參數

PathName
String

必要。 指定檔名的字串運算式。 PathName 可包括目錄或資料夾及磁碟機。

Attributes
FileAttribute

必要。 常數或數值運算式,其總和可以表示檔案屬性。

例外狀況

Attribute 類型無效。

範例

此範例會使用函 SetAttr 式來設定檔案的屬性。

' Set hidden attribute.
SetAttr("TESTFILE", vbHidden)
' Set hidden and read-only attributes.
SetAttr("TESTFILE", vbHidden Or vbReadOnly)

備註

如果您嘗試設定開啟檔案的屬性,就會發生運行時錯誤。

Attributes 變數列舉值如下所示:

常數 描述
Normal vbNormal 一般 (預設) 。
ReadOnly vbReadOnly 唯讀。
Hidden vbHidden 隱藏。
System vbSystem 系統檔案。
Volume vbVolume 磁碟區標籤
Directory vbDirectory 目錄或資料夾。
Archive vbArchive 前次備份之後,檔案已經有了變更。
Alias vbAlias 檔案有不同的名稱。

注意

這些列舉類型 (Enumeration) 是由 Visual Basic 語言所指定。 您可以在程式代碼中的任何位置使用名稱,而不是實際值。

適用於

另請參閱