N number of CSV file to combine into one file. and the data must reside side by side, Something like this
DatTime_M1 Voltage Currency| Dattime_m2 Volage currency |.....DatTime_N Vol Curr
2016-04-29 237.1 3.54 2016-04-29 237.1 3.54 2016-04-29 237.1 3.54
2016-04-29 237.7 3.54 2016-04-29 237.1 3.54 2016-04-29 237.1 3.54
2016-04-29 236.4 3.54 2016-04-29 237.1 3.54 2016-04-29 237.1 3.54
2016-04-29 236.4 3.53 2016-04-29 237.1 3.54 2016-04-29 237.1 3.54
I have written a code where instead of above merge in simply merges or appends in the same row.
string[] files = (Directory.GetFiles(txtConsolidated_OS_CSV.Text.Trim()));
foreach (var file in files)
{
StringBuilder sb = new StringBuilder();
string filename = Path.GetFileNameWithoutExtension(file);
if (file.EndsWith(".csv"))
{
string[] rows = File.ReadAllLines(file);
for (int i = 0; i < rows.Length; i++)
{
if (i == 0)
{
if (counter == 0)
{
sb.Append(rows[i] + "\n");
counter++;
}
}
else
{
sb.Append(rows[i] + "\n");
}
}
}
string csvfile = txtConsolidated_OS_CSV.Text + "\\Merged_OS.csv";
if (File.Exists(csvfile))
{
File.AppendAllText(csvfile, sb.ToString());
sb.Clear();
}
else
{
File.WriteAllText(csvfile, sb.ToString());
sb.Clear();
}