select csv file and add a new column with yes or no and create new csv and move to destination in csharp

Here's one way to select a CSV file, add a new column (with a fixed value of "Yes" or "No"), create a new CSV file with the updated data, and move it to a specified destination:

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

namespace CSVProcessing
{
    class Program
    {
        static void Main(string[] args)
        {
            // Select the CSV file to process
            Console.WriteLine("Select a CSV file to process:");
            var path = Console.ReadLine();

            // Read the CSV file as an array of lines
            var lines = File.ReadAllLines(path);

            // Add a new header column
            var header = lines.First() + ",New Column";
            var newData = new string[lines.Length];
            newData[0] = header;

            // Add a new data column
            for (int i = 1; i < lines.Length; i++)
            {
                newData[i] = lines[i] + ",Yes";
            }

            // Save the updated data to a new CSV file
            var dir = Path.GetDirectoryName(path);
            var fileName = Path.GetFileNameWithoutExtension(path);
            var newFilePath = Path.Combine(dir, fileName + "_new.csv");

            File.WriteAllLines(newFilePath, newData);

            // Move the new CSV file to a specified destination
            Console.WriteLine("Enter the destination path for the new CSV file:");
            var destPath = Console.ReadLine();
            var destFilePath = Path.Combine(destPath, fileName + "_new.csv");

            File.Move(newFilePath, destFilePath);
        }
    }
}
1397 chars
45 lines

Note that this is just one example and there are many ways to achieve the same result.

gistlibby LogSnag