MFC复制文件的简易方法CopyFile

来源:互联网 发布:淘宝森所男装sensu官网 编辑:程序博客网 时间:2024/05/21 07:12

 MFC下可以用CopyFile()函数,其原型如下:

BOOL CopyFile(LPCTSTRlpExistingFileName,// pointer to name ofan existing fileLPCTSTRlpNewFileName, // pointer to filename to copy toBOOL bFailIfExists //flag for operation if file exists);

 其中各参数的意义: 

LPCTSTR lpExistingFileName, // 这个是你要复制的源文件名
LPCTSTR lpNewFileName, // 你要将要复制到的目标文件名 ,务必是包含文件名的全名路径
BOOL bFailIfExists // 如果目标已经存在,不拷贝(True)并返回False,覆盖目标(false)

如:
//拷贝文件c:\log.txt到d:\log.txt,如果D:\log.txt已经存在,就提示导入失败
BOOL m=CopyFile("c:\\log.txt","d:\\log.txt",TRUE); if(!m) MessageBox("文件已经存在,导入失败!");//这里是添加消息提示

参考资料:

http://blog.csdn.net/zacklin/article/details/7440784

0 0