C# 清理IE缓存文件实例代码
文章录入:王子 责任编辑:7747.Net 25
【字体:
小大】
C# 清理IE缓存文件实例代码如下:
using System; using System.IO; using System.Windows.Forms; using System.Text.RegularExpressions; namespace WinFormTemp { public partial class FormTemp : Form { public FormTemp() { InitializeComponent(); this.HelpButton = true; this.MaximizeBox = false; this.MinimizeBox = false; this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。 this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。 this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。 } protected override void OnLoad(EventArgs e) { base.OnLoad(e); DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)); foreach (FileInfo info in dir.GetFiles("*.*", SearchOption.AllDirectories)) { if (Regex.IsMatch(info.Extension, @".(dat|ini)", RegexOptions.IgnoreCase)) // 指定不区分大小写的匹配。 continue; try { info.Delete(); } catch { continue; } } System.Diagnostics.Process.Start(dir.FullName); } protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e) { base.OnHelpButtonClicked(e); e.Cancel = true; FileInfo info = new FileInfo("Clear.bat"); if (info.Exists) info.Attributes = FileAttributes.Normal; using (StreamWriter sw = info.CreateText()) { sw.WriteLine("@echo off"); sw.Write(@"del /f /s /q ""{0}""", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)); } System.Diagnostics.Process.Start(info.DirectoryName); } } }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。