Copy the entire contents of a directory in C#

前端 未结 22 1072
日久生厌
日久生厌 2020-11-22 07:13

I want to copy the entire contents of a directory from one location to another in C#.

There doesn\'t appear to be a way to do this using System.IO class

22条回答
  •  迷失自我
    2020-11-22 07:45

    Try this:

    Process proc = new Process();
    proc.StartInfo.UseShellExecute = true;
    proc.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "xcopy.exe");
    proc.StartInfo.Arguments = @"C:\source C:\destination /E /I";
    proc.Start();
    

    Your xcopy arguments may vary but you get the idea.

提交回复
热议问题