Skip to content

Commit

Permalink
clean-temp-files
Browse files Browse the repository at this point in the history
  • Loading branch information
devspexx committed Aug 5, 2022
1 parent 52cd65b commit 956b65c
Show file tree
Hide file tree
Showing 65 changed files with 1,786 additions and 0 deletions.
25 changes: 25 additions & 0 deletions project-clean-temp-files/cleantempfiles.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32616.157
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cleantempfiles", "cleantempfiles\cleantempfiles.csproj", "{044FB96A-7D49-4DFC-9318-DDFC76DF223A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{044FB96A-7D49-4DFC-9318-DDFC76DF223A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{044FB96A-7D49-4DFC-9318-DDFC76DF223A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{044FB96A-7D49-4DFC-9318-DDFC76DF223A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{044FB96A-7D49-4DFC-9318-DDFC76DF223A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D044A8EC-C4DC-44CB-BBE5-1B283B4FD72C}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions project-clean-temp-files/cleantempfiles/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
4 changes: 4 additions & 0 deletions project-clean-temp-files/cleantempfiles/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>
129 changes: 129 additions & 0 deletions project-clean-temp-files/cleantempfiles/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 140 additions & 0 deletions project-clean-temp-files/cleantempfiles/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cleantempfiles
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

enum RecycleFlags : uint
{
SHERB_NOCONFIRMATION = 0x00000001,
SHERB_NOPROGRESSUI = 0x00000002,
SHERB_NOSOUND = 0x00000004
}
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);

private bool isProgressing = false;

private async void button1_Click(object sender, EventArgs e)
{
if (isProgressing) return;
isProgressing = true;

string path = "C:/Users/" + Environment.UserName + "/AppData/Local/Temp";
string path2 = "C:/Windows/Temp";
string path3 = "C:/temp";

if (!Directory.Exists(path))
{
MessageBox.Show("%TEMP% does not exist:: " + path);
return;
}

List<string> dirs = new List<string>();
List<string> files = new List<string>();

foreach (string dir in Directory.GetDirectories(path, "*.*", SearchOption.AllDirectories))
{
dirs.Add(dir);
label1.Text = "found dir: " + dir;
foreach (string file in Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories))
{
label1.Text = "found file: " + file;
files.Add(file);
}
await Task.Delay(1);
}
foreach (string dir in Directory.GetDirectories(path2, "*.*", SearchOption.AllDirectories))
{
dirs.Add(dir);
label1.Text = "found dir: " + dir;
foreach (string file in Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories))
{
label1.Text = "found file: " + file;
files.Add(file);
}
await Task.Delay(1);
}
if (Directory.Exists("C:/temp"))
{
foreach (string dir in Directory.GetDirectories(path3, "*.*", SearchOption.AllDirectories))
{
dirs.Add(dir);
label1.Text = "found dir: " + dir;
foreach (string file in Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories))
{
label1.Text = "found file: " + file;
files.Add(file);
}
await Task.Delay(1);
}
}

await Task.Delay(1000);
label1.Text = "starting deletion in 3..";
await Task.Delay(1000);
label1.Text = "starting deletion in 2..";
await Task.Delay(1000);
label1.Text = "starting deletion in 1..";
await Task.Delay(1000);
label1.ForeColor = Color.IndianRed;
progressBar1.Maximum = dirs.Count;
foreach (string dir in dirs)
{
progressBar1.Value++;
label1.Text = "deleting: " + dir;

try
{
Directory.Delete(dir, true);
} catch (Exception) { }
await Task.Delay(1);

}

// arg index 1 = If this value is an empty string or NULL, all Recycle Bins on all drives will be emptied.
// arg index 2 = don't show progress reports/confirmation windows
SHEmptyRecycleBin(Handle, null, RecycleFlags.SHERB_NOCONFIRMATION);

label1.Text = "deleted dirs: " + dirs.Count + ", files: " + files.Count;

Application.Restart();
}

private void Form1_Load(object sender, EventArgs e)
{
label3.Text = "C:/Users/" + Environment.UserName + "/AppData/Local/Temp";
}

private void label4_Click(object sender, EventArgs e)
{
Process.Start("explorer", label4.Text);
}

private void label3_Click(object sender, EventArgs e)
{
Process.Start("explorer", label3.Text);
}

private void label2_Click(object sender, EventArgs e)
{
Process.Start("explorer", label2.Text);
}
}
}
Loading

0 comments on commit 956b65c

Please sign in to comment.