How do I delete a directory with read-only files in C#?
问题 I need to delete a directory that contains read-only files. Which approach is better: Using DirectoryInfo.Delete() , or, ManagementObject.InvokeMethod(\"Delete\") ? With DirectoryInfo.Delete() , I have to manually turn off the read-only attribute for each file, but ManagementObject.InvokeMethod(\"Delete\") doesn\'t appear to need to. Is there any situation where one is more preferable to the other? Sample code (test.txt is read only). First way: DirectoryInfo dir = new DirectoryInfo(@\"C:\