Reputation: 910
I'm trying to copy a file over to a networked folder on a mapped drive. I tested out COPY in my command line which worked, so I thought I'd try automating the process within C#.
ProcessStartInfo PInfo;
Process P;
PInfo = new ProcessStartInfo("COPY \"" + "c:\\test\\test.txt" + "\" \"" + "w:\\test\\what.txt" + "\"", @"/Z");
PInfo.CreateNoWindow = false; //nowindow
PInfo.UseShellExecute = true; //use shell
P = Process.Start(PInfo);
P.WaitForExit(5000); //give it some time to finish
P.Close();
Raises an exception : System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
What am I missing? Would I have to add anything else to the command parameters?
I've tried File.Copy but it doesn't appear to work (File.Exists("<mappeddriveletter>:\\folder\\file.txt");
) brings up false.
Upvotes: 1
Views: 1411
Reputation: 20044
This SO post contains an example
how to do it right. You need to call cmd.exe
with /c copy
as a parameter.
Upvotes: 2
Reputation: 2394
Well, for the technical bit: copy
in itself is not an executable, but merely a command interpreted by cmd
. So basically, you'd have to start cmd.exe
as a process, and pass it a flag that makes it run the copy
command (which you'll also have to supply as a parameter).
Anyways, I'd side with Promit and recommend looking into File.Copy
or something similar.
e: Ah, missed your comment on Promit's answer when I posted this.
Upvotes: 2