C# win Forms
hi. CMD windows keeps saying “the system cannot find file specified”
If I type in the command in CMD window “copy /b myfile.txt test.txt” it works :S
btw.: is there a way to actually see the command getting executed in the CMD window ?
public void OutputBtn_Process_Click(object sender, EventArgs e)
{
foreach (FileInfo fi in listBox1.Items)
{
Process process1 = new Process();
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.Arguments = "copy /b \""+fi.Name+"\"test.txt";
//process1.StartInfo.LoadUserProfile = true;
process1.StartInfo.FileName = "cmd.exe\"/k";
process1.StartInfo.WorkingDirectory = Path.GetDirectoryName(fi.FullName);
process1.Start();
process1.Dispose();
process1.Close();
}
}
The /K is an argument and should be in the Arguments property not on the FileName property
(and, of course L.B. is right when he suggests to put a space in front of test.txt)
By the way, your code, as written, loops on a listbox and, in each loop, re-write the file test.txt with the contents of the current FileInfo item. In this way, the last file in the list will be the one who its content is copied to test.txt. Is this logic correct?