搜索文件名包含 [英] search the filename contaions
本文介绍了搜索文件名包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾经使用以下搜索文件名
I used to search the file names using below
Directory.GetFiles(@"C:/", "*.aspx", SearchOption.AllDirectories).First(f => System.IO.Path.GetFileName(f).Contains("data"))
当带有data的文件名不包含它时显示错误为序列包含没有匹配元素我想跳过其他条件而不显示此错误我该如何解决...
请求帮助我
when a file name with "data" doesn't contains it showing the error as "Sequence contains no matching element" i want to skip to else conditions without showing this error how can i solve...
pleas help me
推荐答案
您应该使用FirstOrDefault()
代替First()
,然后测试结果null
。
You should useFirstOrDefault()
in place ofFirst()
, then to test the result fornull
.
这篇关于搜索文件名包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文