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

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

问题描述

如何在C#中使用 DirectoryInfo.GetFiles 函数找到两个文件类型* .gif和* .jpg?



当我尝试这个代码:

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

异常路径中的非法字符。被抛出。

解决方案

你不能这样做。您需要使用 GetFiles()方法。或者您可以使用数组作为扩展名,然后检查其中的每一个,但仍然需要多次使用此方法。



查看这些问题; / p>


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

When I try this code:

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

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

解决方案

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.

Check out these questions;

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

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