0

Can someone please help me out with the syntax here

string sourcePath = @textBox2.Text.ToString();
string targetPath = @textBox1.Text.ToString();

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"XCOPY C:\folder D:\Backup\folder /i");

psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process copyFolders = System.Diagnostics.Process.Start(psi);
copyFolders.WaitForExit();

I am trying to change this line below to replace c:\folder with (sourcePath) and D:\Backup\folder with targetPath

(@"XCOPY C:\folder D:\Backup\folder /i");

I keep getting source not found when I messagebox like this it looks ok

MessageBox.Show(@"XCOPY " + (sourcePath) + (targetPath) + " /i");
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Zen
  • 29
  • 1
  • 1
  • 6

2 Answers2

0

Nothing there really looks wrong. Perhaps debug it so you can get the text out of it and copy/paste it to Explorer to make sure the paths are valid and there's nothing funky going on?

Also, you don't need to do .ToString() on the .Text property of a TextBox. it's already a string.

Tim
  • 14,999
  • 1
  • 45
  • 68
0

You'll need to debug, I'd start here:

string args = string.format("{0} {1} /i", sourcePath, targetPath);
Debug.WriteLine(args);
//verify your paths (both) are correct

string cmd = string.format("XCOPY {0}", args);
Debug.WriteLine(cmd);
//copy the command and test it out directly in cmd

Also, try passing your arguments....as arguments....

System.Diagnostics.ProcessStartInfo psi = 
  new System.Diagnostics.ProcessStartInfo("XCOPY", args);

You can look at the documentation for an example of passing with arguments

Mike C.
  • 3,024
  • 2
  • 21
  • 18
  • Thanks Mike C that works using this code string args = (sourcePath) + " " + (targetPath); System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("XCOPY", args + " /i"); – Zen Jul 08 '13 at 14:50