-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (53 loc) · 1.93 KB
/
Program.cs
File metadata and controls
58 lines (53 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
ulong totalSize = 0;
#region Credits
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("Made by: ");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("LuisAlfredo92");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(": https://github.com/LuisAlfredo92/AMD-Cleaner");
#endregion
Console.WriteLine("Starting...");
// It will delete all the content on the AMD folder. It's harmless
foreach (var folder in Directory.GetDirectories(@"C:\AMD"))
{
try
{
// Gets the folder size
ulong size = (ulong)new DirectoryInfo(folder).EnumerateFiles("*", SearchOption.AllDirectories).Sum(fi => fi.Length);
totalSize += size;
Directory.Delete(folder, true);
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Deleted: ");
Console.ForegroundColor = ConsoleColor.White;
Console.Write(folder);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($" ({FormatBytes(size)})");
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"There was an error while trying to delete {folder}: {ex.Message}");
}
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Done!");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"Cleaned space: {FormatBytes(totalSize)}");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Finished!, press any key to continue");
Console.ReadLine();
/* Thanks to https://stackoverflow.com/a/2082893/11756870
* I made some little changes to get an ulong instead of long
* and to simplify the code */
static string FormatBytes(ulong bytes)
{
string[] Suffix = { "B", "KB", "MB", "GB", "TB" };
int i;
double dblSByte = bytes;
for (i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024)
{
dblSByte = bytes / 1024.0;
}
return string.Format("{0:0.##} {1}", dblSByte, Suffix[i]);
}