pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

technobuff private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Sujeeth on Wed 26 Mar 10:45
report abuse | download | new post

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace TemporaryFilesRemoval
  8. {
  9.     class Program
  10.     {
  11.         /// <summary>
  12.         /// The main entry point for the application.
  13.         /// </summary>
  14.         [STAThread]
  15.         static void Main(string[] args)
  16.         {
  17.             Console.Title = "Temporary LOG Files Removal";
  18.  
  19.             DeleteFiles("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\LOGS", "*.log");
  20.             DeleteFolder("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\LOGS", "*.log");
  21.  
  22.             DeleteFiles("D:\\Sharepoint Logs", "*.log");
  23.             DeleteFiles("C:\\Documents and Settings\\Default User\\Local Settings\\Temp", "*.log");
  24.         }
  25.         static void DeleteFolder(string rootfolder, string filter)
  26.         {
  27.             try
  28.             {
  29.                 string[] directories = System.IO.Directory.GetDirectories(rootfolder);
  30.                 Console.WriteLine(string.Format("Total {0} directories in {1}", (directories.Length), rootfolder));
  31.                 foreach (string dir in directories)
  32.                 {
  33.                     DeleteFiles(dir, filter);
  34.                     DeleteFolder(dir, filter);
  35.                     try
  36.                     {
  37.                         Console.WriteLine(string.Format("Deleting directory : {0}", dir));
  38.                         System.IO.Directory.Delete(dir);
  39.                         Console.WriteLine(string.Format("{0} has been deleted.", dir));
  40.                     }
  41.                     catch (Exception ex)
  42.                     {
  43.                         Console.WriteLine(string.Format("Error : {0}", ex.Message));
  44.                         Console.WriteLine();
  45.                     }
  46.                 }
  47.             }
  48.             catch (Exception ex)
  49.             {
  50.                 Console.WriteLine(string.Format("Error : {0}", ex.Message));
  51.                 Console.WriteLine();
  52.             }
  53.  
  54.         }
  55.         static void DeleteFiles(string folder, string filter)
  56.         {
  57.             string[] files = null;
  58.             try
  59.             {
  60.                 if (!string.IsNullOrEmpty(filter))
  61.                 {
  62.                     files = System.IO.Directory.GetFiles(folder, filter);
  63.                 }
  64.                 else
  65.                 {
  66.                     files = System.IO.Directory.GetFiles(folder);
  67.                 }
  68.  
  69.                 Console.WriteLine(string.Format("Total {0} file(s) in {1}", (files.Length), folder));
  70.                 Console.WriteLine();
  71.  
  72.                 foreach (string file in files)
  73.                 {
  74.                     Console.WriteLine(string.Format("Deleting {0}", file));
  75.                     System.IO.File.Delete(file);
  76.                     Console.WriteLine(string.Format("{0} has been deleted.", file));
  77.                     Console.WriteLine();
  78.                 }
  79.             }
  80.             catch (Exception ex)
  81.             {
  82.                 Console.WriteLine(string.Format("Error : {0}", ex.Message));
  83.                 Console.WriteLine();
  84.             }
  85.  
  86.         }
  87.     }
  88. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post