我最近看到this tutorial(请在程序前看到)。我试过了,它工作正常。 我想编写一个程序,使用GUI完成相同的结果。见图像 -
具体来说,我希望c#等价于:
Copy \B SrcImage + SrcArchive Result
其中SrcImage
,SrcArchive
和Result
是指向三个文件的字符串。
有谁知道我能做什么?
更新#1: 我试过这个:
//Writing a batch file containing the desired code in batch file
//language, and running it from a c# form.
string BackSlashB = "-b";
string lines = "@echo off \r copy "+ BackSlashB +" " + SrcJpg + " + " + SrcRar + " " + Destfile + " \r pause";
MessageBox.Show(lines);
System.IO.StreamWriter batchfile = new System.IO.StreamWriter("c:\\temp.bat");
batchfile.WriteLine(lines);
batchfile.Close();
System.Diagnostics.Process.Start("c:\\temp.bat");
在我阅读它的内容之前,控制台窗口打开然后消失... 有什么想法吗?
答案 0 :(得分:0)
好吧,我终于开始工作了。
问题在于\ r \ n逃脱。由于一些奇怪的原因,它必须是\ r \ n,否则批处理文件将包含一行代码。 另外,我不得不在每个文件名周围添加撇号。 最后,我删除了暂停和调试框,将其替换为"检查文件是否存在"以便向用户提供任务已完成的消息。
整个代码:
string lines = "@echo off" + "\r\n copy /b " + "\"" + SrcJpg + "\"" + " + " + "\"" + SrcRar + "\"" + " " + "\"" + Destfile + "\"";
//MessageBox.Show(lines);
System.IO.StreamWriter batchfile = new System.IO.StreamWriter("c:\\temp.bat");
batchfile.WriteLine(lines);
batchfile.Close();
System.Diagnostics.Process.Start("c:\\temp.bat");
if (File.Exists(Destfile))
{
MessageBox.Show("File Created!");
}