public static void ForceDelete(string p_strPath)
{
for (Int32 i = 0; i < 5; i++)
{
try
{
if (File.Exists(p_strPath))
File.Delete(p_strPath);
else if (Directory.Exists(p_strPath))
Directory.Delete(p_strPath, true);
return;
}
catch (Exception e)
{
if (!(e is IOException || e is UnauthorizedAccessException || e is DirectoryNotFoundException))
throw;
try
{
ClearAttributes(p_strPath, true);
}
catch (Exception ex)
{
if (!(ex is ArgumentException || ex is DirectoryNotFoundException))
throw;
//we couldn't clear the attributes
}
}
}
}