How do I change the Read-only file attribute for each file in a folder using c#?

前端 未结 4 1159
礼貌的吻别
礼貌的吻别 2021-02-14 18:11

How do I change the Read-only file attribute for each file in a folder using c#?

Thanks

4条回答
  •  借酒劲吻你
    2021-02-14 18:47

    foreach (string fileName in System.IO.Directory.GetFiles(path))
    {
        System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
    
        fileInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
        // or
        fileInfo.IsReadOnly = true;
    }
    

提交回复
热议问题