垃圾清理软件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using System.IO;

namespace RubishClear
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region "全局的私有变量"

//设置需要清理的文件夹共5个;
public string[] _RubishPath=new string [5];
//设置用户名.;
string _UserName="";
//设置筛选分隔符;
char[] _split = new char[1] { '\\' };
//设置总文件大小的变量
long _AllMemory = 0;
#endregion

//获取文件夹的路径
void getRubishPath()
{
//获取当前的用户名.方法很多的.//
Microsoft.VisualBasic.Devices.ServerComputer sc = new Microsoft.VisualBasic.Devices.ServerComputer();
string[] All = sc.FileSystem.SpecialDirectories.MyDocuments.Split(_split);
_UserName = All[2];

_RubishPath.SetValue(@"C:\WINDOWS\SoftwareDistribution\Download\", 0);
_RubishPath.SetValue(@"C:\WINDOWS\$hf_mig$\", 2);
_RubishPath.SetValue(sc.FileSystem.SpecialDirectories.Temp + @"\", 3);
// MessageBox.Show(sc.FileSystem.SpecialDirectories.Temp);
_RubishPath.SetValue(@"C:\Documents and Settings\" + _UserName + @"\Recent\", 1);
_RubishPath.SetValue(@"C:\WINDOWS\ie7updates\", 4);
}

//获取垃圾文件的名字&获取要删除的文件的大小./
void getFilename()
{
try
{
foreach (string path in _RubishPath)
{
// string[] arr = Microsoft.VisualBasic.FileIO.FileSystem.GetDirectories(path);

foreach
(string _FileName in Microsoft.VisualBasic.FileIO.FileSystem.GetFiles(path,Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories))
{
try
{
FileInfo fi = new FileInfo(_FileName);//获取文件的所有信息.

_AllMemory += fi.Length;//删除的文件的大小叠加起来.

Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(_FileName);//删除文件.本人原来使用的是VB所以vb的东西搬了过来.
//fi.Delete();//也可以使用fi.edlete事件.

this.listBox1.Items.Add(_FileName);//添加删除的文件.
}
catch (Exception exp)
{
this.listBox2.Items.Add(exp.Message);//添加没有删除的文件.
continue;//如果错误继续执行.
}
}
}
}
catch
{ }
}

//获取&删除垃圾文件夹/
void getDic()
{
try
{
foreach (string path in _RubishPath)
{
foreach
(string _PName in Microsoft.VisualBasic.FileIO.FileSystem.GetDirectories(path, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories))
{
try
{
Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory
(_PName,Microsoft.VisualBasic.FileIO.DeleteDirectoryOption.DeleteAllContents);//删除文件.本人原来使用的是VB所以vb的东西搬了过来.
this.listBox1.Items.Add(_PName);//添加删除文件夹.
}
catch (Exception exp)
{
this.listBox2.Items.Add(exp.Message);//添加没有删除的文件夹.
continue;//如果错误继续执行.
}
}
}
}
catch { }
}

//登录事件
private void Form1_Load(object sender, EventArgs e)
{
getRubishPath();
}

//chilk事件
private void button1_Click(object sender, EventArgs e)
{
getFilename();//开始清空文件.
System.Threading.Thread.Sleep(100);//线程睡眠100毫秒.
getDic();//开始清空文件夹.
la1.Text = "程序共清空了:" + (int)(_AllMemory / 1024) + "K的垃圾文件";

MessageBox .Show ("已经成功删除了"+this.listBox1.Items.Count.ToString()+"项垃圾文件!");
}
}
}

转载于:https://www.cnblogs.com/watchfluture/p/4899220.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值