DirectoryInfo.GetFiles,如何获得在C#中不同类型的文件 [英] DirectoryInfo.GetFiles, How to get different types of files in C#

查看:1635
本文介绍了DirectoryInfo.GetFiles,如何获得在C#中不同类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何才能找到这两种类型的文件* .gif和* .JPG使用 DirectoryInfo.GetFiles 在C#中的功能?

How can I find both file types *.gif and *.jpg using DirectoryInfo.GetFiles function in C# ?

当我试试这个代码:

string pattern = "*.gif|*.jpg";
FileInfo[] files = dir.GetFiles(pattern);



例外路径中具有非法字符。被抛出。

The exception "Illegal characters in path." is thrown.

推荐答案

您不能这样做。您需要使用的GetFiles()方法逐一。或者你可以使用数组为您的扩展,然后检查他们每个人,但它仍然是你也需要这种方法不止一次

You can't do that. You need to use GetFiles() method each one of them. Or you can use an array for your extensions and then check each one of them but it is still also you need this method more than once.

看看这些问题;

  • GetFiles with multiple extentions
  • Can you call Directory.GetFiles() with multiple filters?

这篇关于DirectoryInfo.GetFiles,如何获得在C#中不同类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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