VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > C#编程 >
  • C#教程之C#中获取指定路径下指定后缀名的所有文件的路径的list

本站最新发布   C#从入门到精通
试听地址  
https://www.xin3721.com/eschool/CSharpxin3721/

场景

指定一个路径和后缀名,查找这个路径下所有以此后缀名结尾的文件。

注:

博客主页:
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就是一个指定的路径

然后第二个参数是指定后缀名

相关教程