想用C#列出所有图像文件的文件夹中 [英] Want to list all Image Files in a folder using C#

查看:156
本文介绍了想用C#列出所有图像文件的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:结果
多一些推广的GetFiles






有没有像GetFiles的,需要一个功能更多的则1文件类型如

  DirectoryInfo的DI =新DirectoryInfo的(C:/的Inetpub / wwwroot文件/演示); 
的FileInfo [] = rgFiles di.GetFiles(* BMP,* .JPG,等等。);


解决方案

据我所知,这是不能直接成为可能。



相反,你可以让每一个文件,然后过滤数组:

  HashSet的<串GT; allowedExtensions =新的HashSet<串GT;(extensionArray,StringComparer.OrdinalIgnoreCase); 
的FileInfo [] =文件Array.FindAll(dirInfo.GetFiles(),F => allowedExtensions.Contains(f.Extension));



extensionArray 必须包括每个扩展之前,但不区分大小写。


Possible Duplicate:
GetFiles with multiple extentions

is there a function like GetFiles that takes more then 1 file type like

DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/demos");
FileInfo[] rgFiles = di.GetFiles("*.bmp, *.jpg, etc");

解决方案

AFAIK, this isn't directly possible.

Instead, you can get every file, then filter the array:

HashSet<string> allowedExtensions = new HashSet<string>(extensionArray, StringComparer.OrdinalIgnoreCase);
FileInfo[] files = Array.FindAll(dirInfo.GetFiles(), f => allowedExtensions.Contains(f.Extension));

extensionArray must include . before each extension, but is case-insensitive.

这篇关于想用C#列出所有图像文件的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆