Created
February 21, 2022 14:50
-
-
Save bradmartin333/38d0046cb9262162cc322bc9624b0394 to your computer and use it in GitHub Desktop.
Easy way to clean out frequently used archive folders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
namespace FolderCleaner | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
FileInfo director = new FileInfo($@"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}\director.txt"); | |
if (!director.Exists) | |
{ | |
Console.WriteLine($"{director.FullName} not found.\nPress any key to exit."); | |
Console.ReadKey(); | |
return; | |
} | |
Console.WriteLine($"Reading folders to clean from {director.FullName}"); | |
DirectoryInfo[] dirs = File.ReadLines(director.FullName).Select(x => new DirectoryInfo(x)).ToArray(); | |
foreach (DirectoryInfo dir in dirs) | |
{ | |
if (!dir.Exists) | |
{ | |
Console.WriteLine($"\n{dir.FullName} not found, skipping..."); | |
continue; | |
} | |
Console.WriteLine($"\nEntering {dir}"); | |
if (dir.GetFiles().Length == 0) Console.WriteLine("No files found"); | |
foreach (FileInfo file in dir.GetFiles()) | |
{ | |
Console.WriteLine($"\tDeleting {file.FullName}"); | |
file.Delete(); | |
} | |
} | |
Console.WriteLine("\nFolderClean complete.\nPress any key to exit."); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment