문제

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");
도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top