我有 22 个 .csv 文件要读取并写入 1 个 .csv 文件 这是我的内部课程
internal class Record
{
[Name("RptDt")]
public string Date { get; set; }
[Name("Entity")]
public string Entity { get; set; }
[Name("ProdFamily")]
public string ProdFamily { get; set; }
[Name("ProdGroup")]
public string ProdGroup { get; set; }
[Name("ProdType1")]
public string ProdType1 { get; set; }
[Name("ProdTypo")]
public string ProdTypo { get; set; }
[Name("ProdType")]
public string Buy { get; set; }
[Name("Principal")]
public string Principal { get; set; }
}
这是读写代码
string[] files = Directory.GetFiles(fbd.SelectedPath, "*.csv", SearchOption.AllDirectories);
string numberFile = files.Length.ToString();
using (var writer = new StreamWriter(SaveTxt.Text + "\\Result_" + MonthCB.Text + "_" + YearCB.Text + ".csv"))
using (var csvOut = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
for (int i = 0; i < Int16.Parse(numberFile); i++)
{
using (var reader = new StreamReader(files[i]))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var records = csv.GetRecords<Record>();
csvOut.WriteRecords(records);
}
}
}
但是,代码仅从前 2 个 .csv 文件写入数据。我应该如何解决这个问题?