List data = new List();
foreach (var file in Dictionary.GetFiles("e:\華新采集", "*.txt"))
{
data.AddRange(File.ReadAllLines(file).Skip(2));
}
var query = data.Select(x => x.Split('\t')).GroupBy(x => x[1]).OrderBy(x => x.Key).Select((x, i) => string.Format("{0}\t{1}\t{2}", i + 1, x.Key, x.Sum(y => int.Parse(y[2]))));
File.WriteAllLines("aaa.txt", query);
這個程序現在不同文件名字相同也合並了,這個不要合並,怎麼修改?
data.AddRange(File.ReadAllLines(file).Skip(2).GroupBy(x => x.Split('\t')[1]).Select(x => new { name = x.Key, value = int.Parse(x.Split(' ')[2]).Sum()}));