public static void DeleteDirectory(string path, bool recursive) { if (recursive) { var succeeded = DirectoryUtilities.DeleteDirectoryRobust(path); if (!succeeded) { throw new IOException("Could not delete directory " + path); } } else { RetryUtility.Retry(() => Directory.Delete(path, false)); } }
// See comment on class above regarding Dispose public void Dispose() { if (_detached) { return; } try { File.Delete(Path); } catch (IOException e) { // We tried, but we don't want to crash just because virus scanner or similar won't release the file. Logger.WriteMinorEvent("Could not delete temp file during Dispose(): " + e.Message); Debug.Fail("Could not delete temp file during Dispose(): " + e.Message, e.ToString()); } if (_folderToDelete != null) { DirectoryUtilities.DeleteDirectoryRobust(_folderToDelete); } }