本文介绍了如何通过部分名称查找文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取完整的文件名?
How can I get the full filename?
例如:
我有一个名为 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);
}
}
这篇关于如何通过部分名称查找文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!