﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;

public class gestionfichier : MonoBehaviour
{
    [SerializeField] private TMPro.TMP_InputField groupe;
    [SerializeField] private TMPro.TMP_InputField ident;
    [SerializeField] private Button creation;
    [SerializeField] private string nom_QCM;
    [HideInInspector] public string chemin;

    private string path = "";

    // Start is called before the first frame update
    void Start()
    {
        creation.onClick.AddListener(Creationfichier);
    }

    void Creationfichier()
    {
        path = Application.streamingAssetsPath + "/" + nom_QCM + "/" + groupe.text;

        if (Directory.Exists(path) == false)
        {
            Directory.CreateDirectory(path);
            //Debug.LogError("Create Folder " + pathToStudent);
        }
        else
        {
            Debug.Log("Folder existe at " + path);
        }

        chemin = path + "/" + ident.text + ".csv";
        string resultat = "candidat:;" + ident.text + "\n";
        File.WriteAllText(chemin, resultat);

        creation.gameObject.SetActive(false);
        creation.onClick.RemoveListener(Creationfichier);
    }
}
