public static ForceDelete ( string p_strPath ) : void | ||
p_strPath | string | The path to delete. |
return | void |
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
}
}
}
}
/// <summary> /// Ends a read-only transaction. /// </summary> /// <remarks> /// This takes the archive out of read-only mode, and releases any used resources. /// </remarks> public void EndReadOnlyTransaction() { if (m_szeReadOnlyExtractor != null) { m_szeReadOnlyExtractor.Dispose(); } m_szeReadOnlyExtractor = null; if (!String.IsNullOrEmpty(m_strReadOnlyTempDirectory)) { FileUtil.ForceDelete(m_strReadOnlyTempDirectory); } m_strReadOnlyTempDirectory = null; }