/// <summary>Concatenates the specified output files into one file.</summary> /// <param name="outFiles">The out files.</param> private static void ConcatenateOutputFiles(string[] outFiles, string fileName, string outputFileType) { if (outFiles.Length > 0) { // Assume they are all structured the same i.e. same headings and units. // Read in data from all files. DataTable allData = null; foreach (string outputFileName in outFiles) { DataTable data = null; ApsimTextFile reader = new ApsimTextFile(); try { reader.Open(outputFileName); List <string> constantsToAdd = new List <string>(); constantsToAdd.Add("Title"); data = reader.ToTable(constantsToAdd); } finally { reader.Close(); } if (data != null && data.Columns.Count > 0 && data.Rows.Count > 0) { if (allData == null) { allData = data; } else { DataTableUtilities.CopyRows(data, allData); } } } if (allData != null) { // Move the title column to be first. allData.Columns["Title"].SetOrdinal(0); // Strip off the outputFileType (e.g. Yearly) from the titles. foreach (DataRow row in allData.Rows) { row["Title"] = row["Title"].ToString().Replace(outputFileType, ""); } // Write data. string workingFolder = Path.GetDirectoryName(outFiles[0]); string singleOutputFileName = Path.Combine(workingFolder, fileName); using (StreamWriter outWriter = new StreamWriter(singleOutputFileName)) DataTableUtilities.DataTableToText(allData, 0, ", ", true, outWriter); } // Delete the .out files. foreach (string outputFileName in outFiles) { File.Delete(outputFileName); } } }