在特定文件夹中查找文件 [英] Find File In Specific Folder
本文介绍了在特定文件夹中查找文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
如何在文件夹中查找特定文件。
在WinForm应用程序中
hi
how to find a specific file in a Folder.
in WinForm Application
推荐答案
使用类型System.IO.Directory
中的静态方法。
该方法的名称是GetFiles(...)并带有三个不同的签名:
摘自MSDN:
Use the static methods in the typeSystem.IO.Directory
.
The method's name is GetFiles(...) and comes with three different signatures:
Excerpt from MSDN:
String[] GetFiles(String) //Returns the names of files (including their paths) in the specified directory.
String[] GetFiles(String, String) //Returns the names of files (including their paths) that match the specified search pattern in the specified directory.
String[] GetFiles(String, String, SearchOption) //Returns the names of files (including their paths) that match the specified
search pattern in the specified directory, using a value to determine whether to search subdirectories.
问候,
Using this C# code, a window application can access/find all or a specific file (if mentioned) in a Folder.on load
use
<pre lang="cs">private void Form1_Load(object sender, EventArgs e) {
string[] array1 = Directory.GetFiles(@&quot;C:\MyTemplates&quot;, &quot;*.docx&quot;);
foreach (string name in array1) {
comboBox1.Text = name;
comboBox1.Items.Add(Path.GetFileName(name));
}
}</pre></pre>
这篇关于在特定文件夹中查找文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文