冰楓論壇
標題:
[C#] 切換檔案唯讀屬性切換(唯讀/可讀寫)
[打印本頁]
作者:
whitefox
時間:
2023-6-8 16:20
標題:
[C#] 切換檔案唯讀屬性切換(唯讀/可讀寫)
檔案屬性是複合式的多屬性組合,必須使用 OR 「|」 XOR「^」位元運算子來做遮罩切換
設定為唯讀
string FilePath = @"C:\Test.txt";
File.SetAttributes(FilePath, File.GetAttributes(FilePath) | FileAttributes.ReadOnly);
複製代碼
取消唯讀屬性
string FilePath = @"C:\Test.txt";
File.SetAttributes(FilePath, File.GetAttributes(FilePath) ^ FileAttributes.ReadOnly);
複製代碼
歡迎光臨 冰楓論壇 (https://bingfong.com/)
Powered by 冰楓