Delete directories and files under that method in C #

Scenes

C # according to the folder path to the folder and delete the file folder.

Note:

Blog home page:
https://blog.csdn.net/badao_liumang_qizhi
public concern number
overbearing program ape
acquisition-related programming e-books, tutorials and free downloads push

achieve

New tools, tools create a new method DeleteFolder

/// <summary>
        /// 删除目录
        /// </summary>
        /// <param name="dir">要删除的目录</param>
  public static void DeleteFolder(string dir)
  {
   if (System.IO.Directory.Exists(dir))
   {
    string[] fileSystemEntries = System.IO.Directory.GetFileSystemEntries(dir);
    for (int i = 0; i < fileSystemEntries.Length; i++)
    {
     string text = fileSystemEntries[i];
     if (System.IO.File.Exists(text))
     {
      System.IO.File.Delete(text);
     }
     else
     {
      FileHelper.DeleteFolder(text);
     }
    }
    System.IO.Directory.Delete(dir);
   }
  }

 

Example calls

if (!String.IsNullOrEmpty(nodeData.Id))
    {
         string directoryName = nodeData.Id;

         FileHelper.DeleteFolder(directoryName);
     }

Guess you like

Origin www.cnblogs.com/badaoliumangqizhi/p/12107389.html