我建了一个基于对话框的应用程序,对话框中有一个按钮,点击该按钮,可以执行函数
void CDemoDlg::OnBnClickedButton1()。请问如何在该函数中添加代码,可以实现如下批处理功能:
在当前目录下新建目录newdir,然后复制d:\text1.txt文件到该目录,复制e:\dir1\text2.txt文件到该目录,在该目录下新建文本文件text3.txt,并在该文件中写入字符串"Hello World!"。
谢谢!
void CDemoDlg::OnBnClickedButton1()。请问如何在该函数中添加代码,可以实现如下批处理功能:
在当前目录下新建目录newdir,然后复制d:\text1.txt文件到该目录,复制e:\dir1\text2.txt文件到该目录,在该目录下新建文本文件text3.txt,并在该文件中写入字符串"Hello World!"。
谢谢!
CopyFile()
CreateFile()
@echo off
md newdir
copy d:\text1.txt .
copy e:\dir1\text2.txt
copy con text3.txt
Hello World!
^Z
exit
rem;;;;;;;;;;;;;;;;;;;;;;;;;
然后
void CDemoDlg::OnBnClickedButton1()
{
system("a.bat");
}
MD newdir
CD newdir
COPY D:\text1.txt
COPY E:\dir1\text2.txt
ECHO Hello World!>text3.txt然后在程序里用WinExec或ShellExecute等函数来调用。不过文件操作最好用API来完成。
CopyFile("newdir\\text1.txt", "d:\\text1.txt");
CopyFile("newdir\\text2.txt", "e:\\dir1\\text2.txt");
CStdioFile file(("newdir\\text2.txt", CFile::modeCreate | CFile::modeWrite);
file.WriteString("Hello World!");
CreateDirectory("newdir", NULL);
CopyFile("d:\\text1.txt", "newdir\\text1.txt", 0);
CopyFile("e:\\dir1\\text2.txt", "newdir\\text2.txt", 0);
CStdioFile file(("newdir\\text2.txt", CFile::modeCreate | CFile::modeWrite);
file.WriteString("Hello World!");
------------------------------
那就如goodboyws(深夜不眠者) 所说的做。