How to Copy the entire contents of a directory in C# ?

Below is a sample code snippets that demonstrates how to copy the entire contents of a directory to another in C#.

How to Copy the entire contents of a directory in C# ?

using System;
using System.IO;

namespace AbundantCodeConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var source = @"D:\AbundantcodeFolder1";
            var destination = @"D:\AbundantcodeFolder2";
            // This creates the necessary folders
            foreach (string directory in Directory.GetDirectories(source, "*",
                SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(directory.Replace(source, destination));
            }


            //This copies the necessary files from the source to destination
            foreach (string file in Directory.GetFiles(source, "*.*",
                SearchOption.AllDirectories))
            {
                File.Copy(file, file.Replace(source, destination), true);
            }
        }
    }
    
}