Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Threading;
- namespace App
- {
- class Modules
- {
- public Modules()
- {
- LoadJunkPath(Temp);
- LoadJunkPath(Prefetch);
- LoadJunkPath(Recent);
- }
- private string Temp = Environment.ExpandEnvironmentVariables("%temp%");
- private string Prefetch = Environment.ExpandEnvironmentVariables("%systemroot%") + @"\prefetch";
- private string Recent = Environment.ExpandEnvironmentVariables("%userprofile%") + @"\AppData\Roaming\Microsoft\Windows\Recent";
- private List<string> junkFilePathList = new List<string>();
- private List<string> junkDirectoryPathList = new List<string>();
- private void LoadJunkPath(string junkFolderPath)
- {
- foreach (var filePath in Directory.GetFiles(junkFolderPath))
- {
- junkFilePathList.Add(filePath);
- }
- foreach (var directoryPath in Directory.GetDirectories(junkFolderPath))
- {
- junkDirectoryPathList.Add(directoryPath);
- };
- }
- private void MessageLog(string type, string message)
- {
- Console.ResetColor();
- if(type == "SUCCESS")
- {
- Console.ForegroundColor = ConsoleColor.Green;
- }
- else if (type == "ERROR")
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.White;
- }
- Console.WriteLine(message);
- Console.WriteLine(Environment.NewLine);
- }
- public void Delete()
- {
- foreach (string item in junkFilePathList)
- {
- try
- {
- File.Delete(item);
- MessageLog("SUCCESS", "Deleted: " + item);
- }
- catch (Exception ex) { MessageLog("ERROR", "Error: " + ex.Message); }
- }
- foreach (string item in junkDirectoryPathList)
- {
- try
- {
- Directory.Delete(item, true);
- MessageLog("SUCCESS", "Deleted: " + item);
- }
- catch (Exception ex) { MessageLog("ERROR", "Error: " + ex.Message); }
- }
- Thread.Sleep(5000);
- Environment.Exit(0);
- }
- }
- }
Add Comment
Please, Sign In to add comment