設定或回傳檔案或資料夾的屬性。 根據屬性,可以讀寫或唯讀。
語法
物件。屬性 [= 新屬性]
屬性包含以下部分:
| 部分 | 描述 |
|---|---|
| 物件 | 此為必要動作。 永遠是 檔案 或 資料夾 物件的名稱。 |
| 新屬性 | 選用。 若提供, newattributes 即為指定 物件屬性的新值。 |
設定
newattributes 參數可以是以下任一值,或是以下值的任意邏輯組合。
| 常數 | 值 | 描述 |
|---|---|---|
| 一般 | 0 | 一般檔案。 屬性不會被設定。 |
| ReadOnly | 1 | 唯讀檔案。 屬性是讀寫。 |
| 隱藏 | 2 | 隱藏檔案。 屬性是讀寫。 |
| System | 4 | 系統檔案。 屬性是讀寫。 |
| Volume | 8 | 磁碟機磁碟區標籤。 屬性為唯讀。 |
| Directory | 16 | 資料夾或目錄。 屬性為唯讀。 |
| 封存 | 32 | 檔案自上次備份以來有變動。 屬性是讀寫。 |
| Alias | 1024 | 連結或捷徑。 屬性為唯讀。 |
| 壓縮 | 2048 | 壓縮檔案。 屬性為唯讀。 |
註解
以下程式碼說明了 Attributes 屬性在檔案中的應用。
Sub SetClearArchiveBit(filespec)
Dim fs, f, r
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(fs.GetFileName(filespec))
If f.attributes and 32 Then
r = MsgBox("The Archive bit is set, do you want to clear it?", vbYesNo, "Set/Clear Archive Bit")
If r = vbYes Then
f.attributes = f.attributes - 32
MsgBox "Archive bit is cleared."
Else
MsgBox "Archive bit remains set."
End If
Else
r = MsgBox("The Archive bit is not set. Do you want to set it?", vbYesNo, "Set/Clear Archive Bit")
If r = vbYes Then
f.attributes = f.attributes + 32
MsgBox "Archive bit is set."
Else
MsgBox "Archive bit remains clear."
End If
End If
End Sub
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。