1个回答
展开全部
string keyWord = "苹果";//查找的关键字
string moveToFolder = keyWord + "/";//
DirectoryInfo folder = new DirectoryInfo("textFiles/");
if (folder .Exists )
{
foreach (FileInfo fileName in folder.GetFiles())
{
using (StreamReader reader = new StreamReader(fileName.FullName))
{
if (reader.ReadToEnd().Contains(keyWord))
{
DirectoryInfo newFolder = new DirectoryInfo(moveToFolder);
if (!newFolder .Exists )
{
newFolder.Create();
}
File.Copy(fileName.FullName,moveToFolder+fileName .Name ,true);
}
}
Console.WriteLine(fileName.FullName);
}
}
Console.ReadKey();
string moveToFolder = keyWord + "/";//
DirectoryInfo folder = new DirectoryInfo("textFiles/");
if (folder .Exists )
{
foreach (FileInfo fileName in folder.GetFiles())
{
using (StreamReader reader = new StreamReader(fileName.FullName))
{
if (reader.ReadToEnd().Contains(keyWord))
{
DirectoryInfo newFolder = new DirectoryInfo(moveToFolder);
if (!newFolder .Exists )
{
newFolder.Create();
}
File.Copy(fileName.FullName,moveToFolder+fileName .Name ,true);
}
}
Console.WriteLine(fileName.FullName);
}
}
Console.ReadKey();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询