Copy folder contents from source directory to destination

I’m trying to write a script that will enable me to copy the contents from a source directory to a destination directory using a Boolean trigger.

This is what I have. Something I scraped of the internet.

I get an Error (CS1501): No overload for method ‘RunScript’ takes 2 arguments (line 95)

 private void RunScript(string sourcePath, string destinationPath, bool copy, ref object A)
  {
if (copy)
      if (!System.IO.Directory.Exists(sourcePath))
      {
        Print("Source directory does not exist.");
        return;
      }

    if (!System.IO.Directory.Exists(destinationPath))
      Directory.CreateDirectory(destinationPath);

    foreach (string file in Directory.GetFiles(sourcePath))
    {
      string fileName = Path.GetFileName(file);
      string destFile = Path.Combine(destinationPath, fileName);
      File.Copy(file, destFile, true);
    }

    foreach (string dir in Directory.GetDirectories(sourcePath))
    {
      string dirName = Path.GetFileName(dir);
      string destDir = Path.Combine(destinationPath, dirName);
      RunScript(dir, destDir);
    }

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