本文介绍了如何在目录中查找具有特定名称的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在c#中的名称中包含"ARCHIVE"的目录中找到所有文件.
以下是目录中的示例文件名

Log_726
Log_726_ARCHIVE_20110726080257
Log_726_ARCHIVE_20110726085221

搜索功能应仅返回最后两个文件.

我已经检查了Directory.GetFiles方法,但是当我们需要查找名称以特定字符开头或以特定字符结尾的文件或具有特定扩展名的文件时,似乎可以使用.

我找不到如何搜索文件的名称,文件中包含一些特定的文本.

有人可以帮我吗?

在此先谢谢您.

I have to find all files in a directory which contains "ARCHIVE" in their name in c#.
Below are the sample file name in the directory

Log_726
Log_726_ARCHIVE_20110726080257
Log_726_ARCHIVE_20110726085221

Search function should return only last two files.

I have checked the Directory.GetFiles method, but it seems this works when we need to find a file whose name starts with a particular character or ends with a particular character or files with specific extension.

I could not find how to search files, which contains some particular text in their name.

Can anyone please help me in this?

Thanks in advance.

推荐答案


string[] dirs = Directory.GetFiles(@"c:\", "*ARCHIVE*");


参考: http://msdn.microsoft.com/en-us/library/wz42302f.aspx [< ^ ]并检查以下内容的其他变体相同的功能.


Ref:http://msdn.microsoft.com/en-us/library/wz42302f.aspx[^] and check other variants of the same function.


这篇关于如何在目录中查找具有特定名称的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:16