指定一个路径和后缀名,查找这个路径下所有以此后缀名结尾的文件。
注:
博客主页:
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
新建工具类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就是一个指定的路径
然后第二个参数是指定后缀名
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论