場景
指定一個檔案路徑,獲取當前路徑下所有檔案,并篩選出以指定內容開頭和結尾的檔案,
注:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程式猿
獲取編程相關電子書、教程推送與免費下載,
實作
首先指定前綴和后綴名變數,
string prefix = "TestInfo_"; //實驗資訊組態檔前綴 string ext = ".xml";
然后獲取特定路徑下的所有檔案并遍歷,依次判斷是否含有前綴和后綴,
string directoryPath = Path.GetDirectoryName(node.Id); //獲取指定路徑 //存取所有檔案路徑 List<string> resultList = new List<string>(); System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(directoryPath); System.IO.FileInfo[] files = di.GetFiles(); foreach (System.IO.FileInfo fi in files) { //有組態檔 if (fi.Name.Contains(prefix) && fi.Extension.ToLower() == ext) { resultList.Add(fi.FullName); } } //如果組態檔資訊正常(只有一個組態檔) if (resultList != null && resultList.Count == 1) { string xmlPath = resultList[0]; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/100020.html
標籤:C#
上一篇:C# socket
