static public void DeleteExistingFileOrDirectory(string path)
{
if (Directory.Exists(path))
{
var di = new DirectoryInfo(path);
di.Attributes &= ~FileAttributes.ReadOnly;
foreach (string file in Directory.GetFileSystemEntries(path))
{
DeleteExistingFileOrDirectory(file);
}
Directory.Delete(path);
}
else if (File.Exists(path))
{
File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
File.Delete(path);
}
}