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;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…