日期:2014-05-19  浏览次数:20745 次

求救!!高手们帮帮忙把!

高手们:
        请问怎么用C#编写在本地电脑上进行指定文件或文件夹的搜索,如:指定在D盘下查找所有文件名为 "1 "的所有文件??????

------解决方案--------------------
My.Computer.FileSystem.GetFiles( "d:\1.* ")
VS2005专用

==================================================================
博客空间:http://blog.csdn.net/lovingkiss
资源下载:http://download.csdn.net/user/lovingkiss
Email:loving-kiss@163.com
本人说明: <我的帖子我做主,结贴率保持100%>
优惠接单开发,信誉保证,Q64180940(请清楚注明业务还是技术咨询)
==================================================================
------解决方案--------------------
例如:
For Each foundFile As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments, True, "*.dll ")
ListBox1.Items.Add( foundFile )
Next

C#写法:
foreach (string foundFile in My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyDocuments, true, "*.dll ")) {
ListBox1.Items.Add(foundFile);
}

------解决方案--------------------
string[] files = Directory.GetFiles( "d:\ ");

if(files.Length > 0)
{
foreach(string s in files)
{
if(s.Contain( "1 "))
{
//文件名中含有1
}
}
}
------解决方案--------------------
/// <summary>
/// Search path and its subpath for searchPattern
/// </summary>
/// <param name= "path "> </param>
/// <param name= "searchPattern "> </param>
/// <returns> </returns>
public static string[] FindFiles(string path, string searchPattern)
{
List <string> files = new List <string> ();
foreach (string fileName in Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories))
{
files.Add(fileName);
}
return files.ToArray();
}