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");
4

2 回答 2

0

没有什么看起来真的不对。也许调试它,以便您可以从中获取文本并将其复制/粘贴到资源管理器以确保路径有效并且没有任何奇怪的事情发生?

此外,您不需要对TextBox.ToString()的属性进行操作。.Text它已经是一个字符串。

于 2013-07-08T13:40:13.900 回答
0

您需要调试,我将从这里开始:

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

另外,尝试传递你的论点....作为论点....

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

您可以查看文档以获取使用参数传递的示例

于 2013-07-08T14:08:44.343 回答