C# – How to change the Read-only file attribute for each file in a folder using c#

c++

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

Thanks

Best Solution

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;
}