7*24小时应急电话:15927160396
首页 新闻资讯 技术文章
C# 清理IE缓存文件实例代码

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; // 禁用手动调整大小。
17.            this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
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)) // 指定不区分大小写的匹配。
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.}  

版权所有:武汉网福互联科技有限公司    鄂ICP备09022096号
业务QQ:23444550 客服QQ:267052100 电邮:23444550@qq.com  

鄂公网安备 42010602000905号

手机站二维码