If you just want to use RoboCopy in your code, the following code should be enough:
private static void DirectoryCopy1(string sourceDirName, string destDirName,string fileName)
{
using (Process p = new Process())
{
p.StartInfo.Arguments = string.Format("/C ROBOCOPY {0} {1} {2}",
sourceDirName, destDirName, fileName);
p.StartInfo.FileName = "CMD.EXE";
p.StartInfo.UseShellExecute = false;
p.Start();
}
}
If you want to copy the entire folder and all subfolders, the third parameter can be passed "/e".
I used this method to compare with the method in the second link you provided, but the speed of the two methods is almost the same.
However, I still recommend that you use RoboCopy. In the actual copying process, we may have to consider many factors.
RoboCopy provides solutions for many situations, such as "/z", which means that restartable mode is enabled, which can restart after copying fails. This may be useful during network transmission.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.