当前位置:编程学习 > C#/ASP.NET >>

C# 清理IE缓存文件实例代码

C# 清理IE缓存文件实例代码如下:

  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. using System.Text.RegularExpressions;
  5. namespace WinFormTemp
  6. {
  7.     public partial class FormTemp : Form
  8.     {
  9.         public FormTemp()
  10.         {
  11.             InitializeComponent();
  12.             this.HelpButton = true;
  13.             this.MaximizeBox = false;
  14.             this.MinimizeBox = false;
  15.             this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
  16.             this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
  17.             this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
  18.         }
  19.         protected override void OnLoad(EventArgs e)
  20.         {
  21.             base.OnLoad(e);
  22.             DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
  23.             foreach (FileInfo info in dir.GetFiles("*.*", SearchOption.AllDirectories))
  24.             {
  25.                 if (Regex.IsMatch(info.Extension, @".(dat|ini)", RegexOptions.IgnoreCase)) // 指定不区分大小写的匹配。
  26.                     continue;
  27.                 try
  28.                 {
  29.                     info.Delete();
  30.                 }
  31.                 catch
  32.                 {
  33.                     continue;
  34.                 }
  35.             }
  36.             System.Diagnostics.Process.Start(dir.FullName);
  37.         }
  38.         protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
  39.         {
  40.             base.OnHelpButtonClicked(e);
  41.             e.Cancel = true;
  42.             FileInfo info = new FileInfo("Clear.bat");
  43.             if (info.Exists)
  44.                 info.Attributes = FileAttributes.Normal;
  45.             using (StreamWriter sw = info.CreateText())
  46.             {
  47.                 sw.WriteLine("@echo off");
  48.                 sw.Write(@"del /f /s /q ""{0}""", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
  49.             }
  50.             System.Diagnostics.Process.Start(info.DirectoryName);
  51.         }
  52.     }
  53. }  
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,