C#中獲取指定路徑下指定后綴名的所有文件的路徑的list


場景

指定一個路徑和后綴名,查找這個路徑下所有以此后綴名結尾的文件。

注:

博客主頁:
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就是一個指定的路徑

然后第二個參數是指定后綴名

調用結果

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM