有人可以帮我解决这里的语法
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();
我正在尝试更改下面的这一行,用(sourcePath)替换c:\文件夹,用targetPath替换D:\Backup\folder
(@"XCOPY C:\folder D:\Backup\folder /i");
当我这样的消息箱看起来没问题时,我一直找不到来源
MessageBox.Show(@"XCOPY " + (sourcePath) + (targetPath) + " /i");
答案 0 :(得分:0)
没有什么真的看错了。也许调试它,这样你就可以从中获取文本并将其复制/粘贴到资源管理器中,以确保路径有效并且没有什么好玩的东西?
此外,您不需要在TextBox的.ToString()
属性上执行.Text
。它已经是一个字符串。
答案 1 :(得分: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);
您可以查看the documentation以获取使用参数传递的示例