C#中获取指定路径下指定后缀名的所有文件的路径的list
生活随笔
收集整理的這篇文章主要介紹了
C#中获取指定路径下指定后缀名的所有文件的路径的list
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
場景
指定一個路徑和后綴名,查找這個路徑下所有以此后綴名結(jié)尾的文件。
注:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關(guān)注公眾號
霸道的程序猿
獲取編程相關(guān)電子書、教程推送與免費(fèi)下載。
實(shí)現(xiàn)
新建工具類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;}調(diào)用示例
List<string> taskFileList = FileHelper.GetFileListWithExtend(new DirectoryInfo(currentPath), "*.pcj");其中currentpath就是一個指定的路徑
然后第二個參數(shù)是指定后綴名
調(diào)用結(jié)果
?
總結(jié)
以上是生活随笔為你收集整理的C#中获取指定路径下指定后缀名的所有文件的路径的list的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Winform中设置ZedGraph鼠标
- 下一篇: c# char unsigned_dll