File copy using robo copy and process

Biju Thomas picture Biju Thomas · Oct 25, 2011 · Viewed 30.6k times · Source

I am creating a File copy program which will copy large number of files(~100,000) with size ~50 KB using ROBOCOPY command.

For each file, I am creating a new process and passing the ROBOCOPY command and arguments as follow:

using (Process p = new Process)
{
    p.StartInfo.Arguments = string.Format("/C ROBOCOPY {0} {1} {2}", 
            sourceDir, destinationDir, fileName);
    p.StartInfo.FileName = "CMD.EXE";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.UseShellExecute = false;                    
    p.Start();
    p.WaitForExit(); 
} 

Instead of creating a process for each file, I am looking for a better approach, which will be good in terms of performance and design. Can someone suggest a better method?

Answer

xcopy picture xcopy · Apr 22, 2014

This question is a bit old but I thought I would answer to help anyone who still land on it. I wrote a library called RoboSharp (https://github.com/tjscience/RoboSharp) that brings all of the goodness in Robocopy to c#. Take a look if you require the power of Robocopy in c#.