Exemple #1
0
    static void Main(string[] args)
    {
        string logFile = "log.txt";

        // delimiter config
        char inFileDelimiter  = ',';
        char inFileEnclosure  = '"';
        char outFileDelimiter = ';';
        char outFileEnclosure = '"';

        using (StreamWriter logWriter = File.AppendText(logFile))
        {
            try
            {
                if (args.Length == 0)
                {
                    throw new Exception("Das Programm benoetigt mindestens eine Eingabe-Datei!");
                }

                foreach (string inFile in args)
                {
                    CSVFile inCsv = CSVFileReader.Open(inFile,
                                                       Encoding.GetEncoding("iso-8859-1"),
                                                       inFileDelimiter,
                                                       inFileEnclosure
                                                       );

                    CSVFile outCsv = CSVFileConverter.Convert(inCsv);

                    string outFile = inFile + ".konvertiert.csv";

                    CSVFileWriter writer = new CSVFileWriter(outFile,
                                                             Encoding.GetEncoding("iso-8859-1"),
                                                             outFileDelimiter,
                                                             outFileEnclosure
                                                             );

                    writer.WriteCsv(outCsv);
                }
            }
            catch (Exception e)
            {
                logWriter.WriteLine(e.ToString());

                Console.WriteLine("Ein Fehler ist aufgetreten. Weitere Informationen befinden sich in der Log-Datei.\n\n> {0}\n", e.Message);
                Console.WriteLine("Enter zum Beenden druecken...");
                Console.ReadLine();
            }
        }
    }