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

前端 未结 4 1160
礼貌的吻别
礼貌的吻别 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:48

    You can try this : iterate on each file and subdirectory :

    public void Recurse(DirectoryInfo directory)
    {
        foreach (FileInfo fi in directory.GetFiles())
        {
            fi.IsReadOnly = false; // or true
        }
    
        foreach (DirectoryInfo subdir in directory.GetDirectories())
        {
            Recurse(subdir);
        }
    }
    

提交回复
热议问题