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 "Global Private variables"
Set a total of 5 folders to be cleaned;
Public string[] _rubishpath=new string [5];
Set the user name.;
String _username= "";
Set filter separators;
char[] _split = new char[1] {' \ \ '};
Set the total file size variable
Long _allmemory = 0;
#endregion
Get the path to a folder
void Getrubishpath ()
{
Gets the current user name. Methods a lot of.//
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);
}
Get the name of the junk file & get the size of the file you want to delete.
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);//Get all the information for the file.
_allmemory + = fi. length;//the size of the deleted file is superimposed.
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (_filename);//delete the file. I originally used VB so vb things moved over.
Fi. Delete ();//You can also use the Fi.edlete event.
THIS.LISTBOX1.ITEMS.ADD (_filename);//Add deleted files.
}
catch (Exception exp)
{
THIS.LISTBOX2.ITEMS.ADD (exp. Message);//Add files that are not deleted.
continue;//If the error continues to execute.
}
}
}
}
Catch
{ }
}
Get & Delete Trash folder/
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);//delete the file. I originally used VB so vb things moved over.
THIS.LISTBOX1.ITEMS.ADD (_pname);//Add Delete folder.
}
catch (Exception exp)
{
THIS.LISTBOX2.ITEMS.ADD (exp. Message);//Add a folder that is not deleted.
continue;//If the error continues to execute.
}
}
}
}
Catch {}
}
Logon events
private void Form1_Load (object sender, EventArgs e)
{
Getrubishpath ();
}
Chilk Events
private void Button1_Click (object sender, EventArgs e)
{
GetFileName ();//start emptying the file.
System.Threading.Thread.Sleep (100);//thread sleeps 100 milliseconds.
Getdic ();//Start emptying the folder.
La1. Text = "The program has been emptied:" + (int) (_allmemory/1024) + "K junk file";
MessageBox. Show ("has successfully deleted" +this.listbox1.items.count.tostring () + "Item junk file!");
}
}
}
Garbage cleanup Software