从文件夹、其子文件夹和其中的所有文件中删除只读
问题描述:
有没有办法删除只读"属性?
is there a way that i can remove the property "read only"?
我试过这个:
var di = new DirectoryInfo("C:\\Work");
di.Attributes &= ~FileAttributes.ReadOnly;
但它不起作用
答
差不多,试试:
var di = new DirectoryInfo("C:\\Work");
foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
file.Attributes &= ~FileAttributes.ReadOnly;