I have searched the SO but find nothing.
Why this doesn't work?
Directory.Delete(@"E:\3\{90120000-001A-0000-0000-0000000FF1CE}-C");
Above line will throw exception "Access is denied". I have admin rigths and I can delete the dir with Explorer.
It looks like some forbidden chars? but Windows Explorer can handle it. How can I delete directories with names like that?
To work around this issue, use either of the following methods: When you delete the files or folders by using Windows Explorer, use the SHIFT+DELETE key combination. This bypasses the Recycle Bin. Open a command prompt window and then use the rd /s /q command to delete the files or folders.
Select the “Security” tab. Select the “Advanced” button. Select the “Continue” button. Under the “Permissions” tab, select the line that is set to “Deny Everyone” permission, then select “Remove“.
Start a Command Prompt as Administrator by right-clicking on the "Command Prompt" icon in the Windows Start Menu and choose "Run as administrator". Click Continue if you are presented with a confirmation popup message box. In the new command prompt, enter "net user administrator /active:yes".
Thank you all for your input, it helps me in quick find of solution.
As Phil mentioned "Directory.Delete fails if it is, regardless of permissions (see bottom of msdn.microsoft.com/en-us/library/…)"
In addition Unable to remove Read-Only attribute from folder Microsoft says:
You may be unable to remove the Read-Only attribute from a folder using Windows Explorer. In addition, some programs may display error messages when you try to save files to the folder.
Conclusion: always remove all dir,file attributes diffrent then Normal before deleting. So below code solve the problem:
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"E:\3\{90120000-0021-0000-0000-0000000FF1CE}-C1"); if (dir.Exists) { setAttributesNormal(dir); dir.Delete(true); } . . . function setAttributesNormal(DirectoryInfo dir) { foreach (var subDir in dir.GetDirectories()) setAttributesNormal(subDir); foreach (var file in dir.GetFiles()) { file.Attributes = FileAttributes.Normal; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With