指令語法
attrib [+R|-R] [+A|-A] [+S|-S] [+H|-H] [/S] [/D] [路徑\檔案名]
| 參數 | 功能 |
+R / -R | 設定/清除 唯讀屬性 |
+A / -A | 設定/清除 封存屬性 (備份標記) |
+S / -S | 設定/清除 系統屬性 |
+H / -H | 設定/清除 隱藏屬性 |
/S | 處理符合條件的所有子目錄檔案 |
/D | 同時處理目錄本身 (預設僅處理檔案) |
實戰範例
- 移除 D:\books 及所有子資料夾下所有檔案的「唯讀」屬性:
以系統管理員身分執行 cmd:
attrib -R D:\books\*.* /S /D
- 隱藏 D:\Secret 資料夾及其內容:
attrib +H +S D:\Secret /S /D
- 顯示所有隱藏/系統檔案 (遞迴):
attrib -H -S C:\SomeFolder\*.* /S /D
- 清除封存屬性 (標記已備份):
attrib -A D:\Backup\*.* /S
進階:PowerShell 更強大的屬性操作
# 遞迴移除唯讀屬性
Get-ChildItem -Path D:\books -Recurse -Force | ForEach-Object { $_.Attributes = $_.Attributes -band [System.IO.FileAttributes]::ReadOnly }
# 顯示所有隱藏/系統檔案屬性
Get-ChildItem -Path D:\Secret -Recurse -Force | Select-Object Name, Attributes, FullName
常見問題
- 「存取被拒絕」: 需系統管理員權限、或檔案被其他程序鎖定 (用
handle.exe 或「資源監視器」查找)、或檔案在受保護系統目錄 (需 Takeown + Icacls 取得權限)。
- 屬性修改後總管不更新: 按 F5 重新整理、或重啟
explorer.exe。
- 網路磁碟機:
attrib 不支援 UNC 路徑 (\\Server\Share),需對應磁碟機代號或用 PowerShell CIM/WMI。