这是一个关于如何使用 LINQ 执行此操作的示例启动器。我使用LinqPad来玩代码。
var input = "Date: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1 \nDate: 7/30/2013 12:00:00 AM\nSource Path: C:\\FileMoveResults\nDestination Path: C:\\Users\\Documents\\.NET Development\\testing\\ \nLast Folder Updated: 11.0.25.1";
string[] lines = null;
using(var reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(input))))
{
lines = reader.ReadToEnd().Split('\n');
}
IList<Tuple<string, string>> paths = new List<Tuple<string, string>>();
if(lines != null)
{
const int TAKE = 4;
var position = 0;
while(position < lines.Length)
{
var currentLines = lines.Skip(position).Take(TAKE);
paths.Add(Tuple.Create(currentLines.ElementAt(1).Replace("Source Path: ", string.Empty), currentLines.ElementAt(2).Replace("Destination Path: ", string.Empty)));
position = (position + TAKE);
}
}
paths.Dump("Result");
我所做的是收集所有源和目标路径。您可以将其修改为仅根据搜索条件存储所需的内容。
结果看起来像这样,当然我只是一遍又一遍地复制您的示例,因此路径名称没有变化:
Tuple<DictionaryInfo, DictionaryInfo>
如果您想在对象中内置移动和复制能力,我可能还会制作类型的元组。