Ccsafely delete the code of the file directory

From , 5 Years ago, written in C#, viewed 215 times.
URL https://pastebin.vip/view/e9ed9cad
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Retry
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             DirectoryInfo dirInfo = Directory.CreateDirectory(@"C:\TestDir");
  11.  
  12.             string folderName = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\TestDir";
  13.  
  14.             if (!Directory.Exists(folderName))
  15.             {
  16.                 Directory.CreateDirectory(folderName);
  17.                 Console.WriteLine("{0} created! ",folderName);
  18.             }
  19.  
  20.             int retryTimes = 1;
  21.  
  22.             do
  23.             {
  24.                 if (Directory.Exists(folderName))
  25.                 {
  26.                     try
  27.                     {
  28.                         Console.WriteLine("Tring to delete file the {0} time.",retryTimes);
  29.                         Directory.Delete(folderName, true);
  30.                         Console.WriteLine("Deleting file successfully.");
  31.                         break;
  32.                     }
  33.                     catch (IOException ex)
  34.                     {
  35.                         Console.WriteLine("Exception! ", ex.ToString());
  36.                         Console.WriteLine("Sleep 5 seconds and retry.");
  37.                         System.Threading.Thread.Sleep(5000);
  38.                         retryTimes++;
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     Console.WriteLine("Delete folder successfully");
  44.                     break;
  45.                 }
  46.  
  47.             } while (retryTimes <= 5);
  48.  
  49.             if (Directory.Exists(folderName))
  50.                 Console.WriteLine("Deleting folder failed.");
  51.            
  52.             Console.WriteLine("Done");
  53.             Console.ReadKey();
  54.         }
  55.     }
  56. }
  57. //csharp/5415

Reply to "Ccsafely delete the code of the file directory"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website