我最近看过本教程(请在继续之前阅读)。我试过了,效果很好。我想编写一个使用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");
控制台窗口会打开,然后消失,然后我才能阅读其内容...有任何想法吗?
好吧,我终于让它工作了。
问题出在\ r转义。出于某种奇怪的原因,它必须是\ 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!");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句