Tuesday, April 29, 2014

How to run copy command using command line in c# ?

Hi,


I just want to copy a file from one location to other. How should i do it using c#, i want to use the command line commands to do that ?


I have this code that doesn't work :



string command = "copy hello.txt hello4.txt";

System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();

string result = proc.StandardOutput.ReadToEnd();

Console.WriteLine(result);



Please help..!!


No comments:

Post a Comment