Advertisement
Statev

DeleteBinAndObjFolders

Jun 20th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. class DeleteBinAndObjFolders
  5. {
  6.     public static void BinObjFoldersDestroyer(string directoryName)
  7.     {
  8.         DirectoryInfo directory = new DirectoryInfo(directoryName);
  9.  
  10.         foreach (DirectoryInfo subdirectory in directory.GetDirectories())
  11.         {
  12.             BinObjFoldersDestroyer(subdirectory.FullName);
  13.             if (subdirectory.Name == "bin" || subdirectory.Name == "obj")
  14.             {
  15.                 Console.WriteLine(subdirectory.FullName);
  16.                 subdirectory.Delete(true);
  17.             }
  18.         }
  19.     }
  20.  
  21.     public static void StartMenu()
  22.     {
  23.         Console.ForegroundColor = ConsoleColor.Green;
  24.         Console.Write("Folder: ");
  25.         Console.ForegroundColor = ConsoleColor.Gray;
  26.         Console.WriteLine("{0}", Directory.GetCurrentDirectory());
  27.         Console.WriteLine();
  28.         Console.Write("Do you really want to delete all ");
  29.         Console.ForegroundColor = ConsoleColor.Red;
  30.         Console.Write("bin");
  31.         Console.ForegroundColor = ConsoleColor.Gray;
  32.         Console.Write(" and ");
  33.         Console.ForegroundColor = ConsoleColor.Red;
  34.         Console.Write("obj");
  35.         Console.ForegroundColor = ConsoleColor.Gray;
  36.         Console.WriteLine(" folders inside this folder!!!");
  37.     }
  38.  
  39.     static void Main(string[] args)
  40.     {
  41.         StartMenu();
  42.         Console.ReadLine();
  43.         BinObjFoldersDestroyer(Directory.GetCurrentDirectory());
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement