c#中如何查找一个目录下(包含子目录)所有文件中包含某一字符串的所有文件
1个回答
2013-04-22
展开全部
用递归
private void getDirectories(string path)
{
string[] fileNames = Directory.GetFiles(path);
string[] directories = Directory.GetDirectories(path);
foreach (string file in fileNames)
{
Console.WriteLine("Filename:{0}",file);
}
foreach (string dir in directories)
{
Console.WriteLine("Directoriesname:{0}",dir);
getDirectories(dir);
}
}
Console.WriteLine这个地方你可以换成arraylist
private void getDirectories(string path)
{
string[] fileNames = Directory.GetFiles(path);
string[] directories = Directory.GetDirectories(path);
foreach (string file in fileNames)
{
Console.WriteLine("Filename:{0}",file);
}
foreach (string dir in directories)
{
Console.WriteLine("Directoriesname:{0}",dir);
getDirectories(dir);
}
}
Console.WriteLine这个地方你可以换成arraylist
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询