select csv file and for each line add a new column called situation and for each line fill the situation with yes or no and move the new csv to destination in csharp

Here is the code to read a csv file, add a new column called situation and fill it with a yes or no depending on your condition for each row, and then move the new csv file to a destination folder:

main.cs
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        // Get the source file path and destination folder path
        string sourceFilePath = @"C:\data\input.csv";
        string destinationFolder = @"C:\data\output";

        // Read the csv file into a list of string arrays
        var csv = File.ReadAllLines(sourceFilePath)
                      .Select(line => line.Split(',').ToList())
                      .ToList();

        // Add a new column called 'situation' and fill it with yes or no depending on your condition for each row
        for (int i = 0; i < csv.Count; i++)
        {
            bool condition = // your condition here
            csv[i].Add(condition ? "yes" : "no");
        }

        // Write the new csv to a temporary file
        string tempFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".csv");
        using (var writer = new StreamWriter(tempFilePath))
        {
            foreach (var line in csv)
            {
                writer.WriteLine(string.Join(",", line));
            }
        }

        // Move the new csv to the destination folder
        string fileName = Path.GetFileName(sourceFilePath);
        string destinationFilePath = Path.Combine(destinationFolder, fileName);
        File.Move(tempFilePath, destinationFilePath);
    }
}
1382 chars
41 lines

gistlibby LogSnag