場景
C#中根據檔案夾路徑,將檔案夾以及檔案夾下檔案洗掉,
注:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程式猿
獲取編程相關電子書、教程推送與免費下載
實作
新建工具類,工具類中新建方法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); } }
呼叫示例
if (!String.IsNullOrEmpty(nodeData.Id)) { string directoryName = nodeData.Id; FileHelper.DeleteFolder(directoryName); }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/86456.html
標籤:C#
上一篇:C# 重構
下一篇:聊聊c#字串拼接
