場景
指定一個路徑和后綴名,查找這個路徑下所有以此后綴名結尾的檔案,
注:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程式猿
獲取編程相關電子書、教程推送與免費下載,
實作
新建工具類FileHelper,工具類中新建方法GetFileListWithExtend
public static List<string> GetFileListWithExtend(DirectoryInfo directory, string pattern) { List<string> pathList = new List<string>(); string result = String.Empty; if (directory.Exists || pattern.Trim() != string.Empty) { foreach (FileInfo info in directory.GetFiles(pattern)) { result = info.FullName.ToString(); pathList.Add(result); } } return pathList; }
呼叫示例
List<string> taskFileList = FileHelper.GetFileListWithExtend(new DirectoryInfo(currentPath), "*.pcj");
其中currentpath就是一個指定的路徑
然后第二個引數是指定后綴名
呼叫結果

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/103524.html
標籤:C#
上一篇:Winform中設定ZedGraph滑鼠懸浮顯示舉例最近曲線上的點的坐標值和X軸與Y軸的標題
下一篇:使用Newtonsoft序列化
