CopyFile()函数:
作用:Copies an existing file to a new file.(将当前文件复制到新的文件中)
语法:(c++)
BOOL WINAPI CopyFile(
_In_ LPCTSTR lpExistingFileName,
_In_ LPCTSTR lpNewFileName,
_In_ BOOL bFailIfExists
);
参数说明:
lpExistingFileName:
当前文件名,也就是需要拷贝的文件的文件名。(字符串是char数组类型)
lpNewFileName:
新的文件的文件名。(同上,字符串是char数组类型)
bFailIfExists:
按照MSDN上的解释是:
如果bFailIfExists这个参数被设置为true,并且新文件已经在相关的盘符中存在,则函数的返回值为false;而如果参数被设置为false,并且新的文件也已经存在,那么将会覆盖已有的文件,函数返回值为true。
程序示例:
#include<iostream>
#include<windows.h>
#include<string>
using namespace std;
void main(){
string ExistingFile_Path="D:\\test.txt";
string NewFile_Path="C:\\test1.txt";
bool flag;
flag=CopyFile(ExistingFile_Path.c_str(),NewFile_Path.c_str(),false);
if(flag){
cout<<"文件复制成功!"<<endl;
}else{
cout<<"文件复制失败!"<<endl;
}
}