using System;
using System.IO;


namespace fileifondemo
{
    internal class Program
    {
        public const ushort nbelt = 5;

        private static void Main(string[] args)
        {
            string path = @"Z:\Temp\";
            string namefile = "capteur.txt";

            try //Directory.CreateDirectory(path); exexcption
            {
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                FileInfo fic = new FileInfo(path + namefile);
                ConsoleKeyInfo keypressed;
                StreamWriter fictxt = null;

                if (fic.Exists)
                {
                    Console.WriteLine("LE fichier" + namefile + " existe. Souhaitez vous l'écraser?");
                    keypressed = Console.ReadKey(true);
                    if (keypressed.KeyChar != 'O')
                    {
                        fictxt = fic.AppendText();
                    }

                    else
                    {
                        fictxt = fic.CreateText();
                    }
                }
                else
                {
                    fictxt = fic.CreateText();
                }


                fictxt.WriteLine("capteur no;echantillon no;valeur");
                for (int i = 0; i < nbelt; i++)
                {
                    float val;
                    val = (float) Math.Sin((2*Math.PI/nbelt)*i);
                    string concat = "capeur1;" + i + ";" + val;
                    fictxt.WriteLine(concat);
                }
                fictxt.Close();

            }

            catch (Exception e)
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
            }

        }
    }
}


