Copy folder contents from source directory to destination

Found a solution. It copies everything from the source dir with a Boolean trigger.

using System.IO;

private void RunScript(string sourceDir, string destDir, bool copyTrigger, ref object A)
  {
    if(copyTrigger)
    {
      foreach (string dirPath in Directory.GetDirectories(sourceDir, "*", SearchOption.AllDirectories))
        Directory.CreateDirectory(dirPath.Replace(sourceDir, destDir));

      foreach (string newPath in Directory.GetFiles(sourceDir, "*.*", SearchOption.AllDirectories))
        File.Copy(newPath, newPath.Replace(sourceDir, destDir), true);
    }
  }
1 Like