whitefox 發表於 2023-6-8 16:20:54

[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);
頁: [1]
查看完整版本: [C#] 切換檔案唯讀屬性切換(唯讀/可讀寫)