using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace barry.core
{
    class FileOp
    {
        /// <summary>
        /// makes a backup of source in destination
        /// if purge is set to true: destination will be a mirror of source: files which are not in the source will be removed
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="purge"></param>
        public void robocopy(string source, string destination, bool purge = false)
        {
            using (System.Diagnostics.Process p = new System.Diagnostics.Process())
            {
                string purge_opt = "";
                if (purge) { purge_opt = "/Purge"; }

                p.StartInfo.Arguments = String.Format("/C ROBOCOPY {0} {1} /E /XO /w:3 {2} /xf ctrl.barry & pause", source, destination, purge_opt);
                p.StartInfo.FileName = "CMD.EXE";
                p.StartInfo.CreateNoWindow = false;
                p.StartInfo.UseShellExecute = false;
                p.Start();
                p.WaitForExit();
            }
        }


    }
}
