using System.IO; DirectoryInfo sourceDir = new DirectoryInfo(@"C:\Source"); DirectoryInfo destDir = new DirectoryInfo(@"C:\Destination"); if(!destDir.Exists) destDir.Create(); sourceDir.CopyTo(destDir.FullName, true);
using System.IO; DirectoryInfo sourceDir = new DirectoryInfo(@"C:\Source"); DirectoryInfo destDir = new DirectoryInfo(@"C:\Destination\NewFolder"); if(!destDir.Exists) destDir.Create(); sourceDir.CopyTo(destDir.FullName, true);In this example, we use the same `CopyTo` method to copy the source directory, but we pass in a different destination directory path that includes a new folder name. This will create a copy of the source directory with the new name in the destination location. Package library: This method is included in the .NET Framework class library, which is part of the System.IO namespace.