C# 清理IE緩存文件實例代碼
來源:
發(fā)布時間:2010/9/27
瀏覽次數(shù):1455
C# 清理IE緩存文件實例代碼如下:
1.using System;
2.using System.IO;
3.using System.Windows.Forms;
4.using System.Text.RegularExpressions;
5.
6.namespace WinFormTemp
7.{
8. public partial class FormTemp : Form
9. {
10. public FormTemp()
11. {
12. InitializeComponent();
13. this.HelpButton = true;
14. this.MaximizeBox = false;
15. this.MinimizeBox = false;
16. this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手動調(diào)整大小。
17. this.SizeGripStyle = SizeGripStyle.Hide; // 隱藏調(diào)整大小手柄。
18. this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中顯示。
19. }
20.
21. protected override void OnLoad(EventArgs e)
22. {
23. base.OnLoad(e);
24. DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
25. foreach (FileInfo info in dir.GetFiles("*.*", SearchOption.AllDirectories))
26. {
27. if (Regex.IsMatch(info.Extension, @".(dat|ini)", RegexOptions.IgnoreCase)) // 指定不區(qū)分大小寫的匹配。
28. continue;
29. try
30. {
31. info.Delete();
32. }
33. catch
34. {
35. continue;
36. }
37. }
38. System.Diagnostics.Process.Start(dir.FullName);
39. }
40.
41. protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
42. {
43. base.OnHelpButtonClicked(e);
44. e.Cancel = true;
45. FileInfo info = new FileInfo("Clear.bat");
46. if (info.Exists)
47. info.Attributes = FileAttributes.Normal;
48. using (StreamWriter sw = info.CreateText())
49. {
50. sw.WriteLine("@echo off");
51. sw.Write(@"del /f /s /q ""{0}""", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
52. }
53. System.Diagnostics.Process.Start(info.DirectoryName);
54. }
55. }
56.}