Help required in C Sharp code

Hi Everyone,

Require help on the below scenario -

var delimiter = ",";
var allCsv = Directory.EnumerateFiles(@"C:\Users\Documents\UiPath\Files1", "Ansible"+"*.csv", SearchOption.AllDirectories);

string[] header = 
{ 
    "FileName" + delimiter + File.ReadLines(allCsv.First()).First(l => !string.IsNullOrWhiteSpace(l))
};
FileCount = allCsv.Count();
 // Get CSV Data
var mergedData = allCsv.SelectMany(csv =>
	{
		try {
			return File.ReadLines(csv).SkipWhile(l => string.IsNullOrWhiteSpace(l)).Skip(1).Select(ll => (csv.Contains(delimiter) ? "\""+Path.GetFileName(csv)+"\"" :  Path.GetFileName(csv)) + delimiter + ll);
		} catch (Exception e){
			return new string[0];
		}
	}); 

 // skip header of each file
 File.WriteAllLines(@"C:\Users\Documents\UiPath\test1.csv", header.Concat(mergedData));

Above is the C Sharp code which performs merging of multiple CSV files into a single csv file and also catch errors if any, this solution was earlier provided to me by @ptrobot @Yoichi @ppr .

I want a slight modification in this logic -

There is a column name Policy Name which is available in the CSV files and merges along. I want to map it to a different Key value.
For Example - I have a different datatable which have two columns say Policy Name and Value, when the CSV merges I want that Policy Name in the CSV file match with the policy name in the datatable if match found it should pickup the data in value column.

Say, in CSV policy name is “server1” this should check for a match in the other datatable when found it should take the value from there in the below case “xxacdf”

image

Can anyone please help me in this I am stuck.

@ptrobot @Yoichi @ppr can you also have a look and help if possible.

Thanks

Hi @ptrobot @ppr @Palaniyappan @Yoichi @CSharpCoder Can you have a look and provide inputs if any?