如何通过文件的部分名称查找文件? [英] How to find the file by its partial name?
本文介绍了如何通过文件的部分名称查找文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取完整文件名?
例如:
我有一个名为 171_s.jpg
存储在硬盘上。
I have a file named 171_s.jpg
that is stored on the hard disc.
我需要通过文件的部分名称来查找文件,即 171_s
,并获得全名。
I need to find the file by its partial name, i.e. 171_s
, and get the full name.
我该如何实现?
推荐答案
以下是使用GetFiles()的示例:
Here's an example using GetFiles():
static void Main(string[] args)
{
string partialName = "171_s";
DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo(@"c:\");
FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles("*" + partialName + "*.*");
foreach (FileInfo foundFile in filesInDir)
{
string fullName = foundFile.FullName;
Console.WriteLine(fullName);
}
}
这篇关于如何通过文件的部分名称查找文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文