How to remove a single Attribute (e.g. ReadOnly) from a File?

前端 未结 7 1783
南方客
南方客 2020-11-28 08:54

Let say, a file has the following attributes: ReadOnly, Hidden, Archived, System. How can I remove only one Attribute? (for example ReadOnly)

7条回答
  •  我在风中等你
    2020-11-28 09:44

    string file = "file.txt";
    FileAttributes attrs = File.GetAttributes(file);
    if (attrs.HasFlag(FileAttributes.ReadOnly))
        File.SetAttributes(file, attrs & ~FileAttributes.ReadOnly);
    

提交回复
热议问题