新博客地址:程序人生 www.programlife.net 本博客不再更新
Ø CopyFile && MoveFile
BOOL CopyFile(
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
如果文件已经存在,而且bFailIfExists为TRUE则复制失败。
BOOL MoveFile(
LPCTSTR lpExistingFileName, // address of name of the existing file
LPCTSTR lpNewFileName // address of new name for the file
);
程序源码:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
bool bRet = CopyFile(L"Win32API.cpp", L"C://CopyFile.cpp", true);//
if(bRet)
MessageBox(NULL, L"Copy File Succeed!", L"Message", MB_ICONINFORMATION);
bRet = MoveFile(L"Win32API.cpp", L"D://CopyFile.cpp");
if(bRet)
MessageBox(NULL, L"Move File Succeed!", L"Message", MB_ICONINFORMATION);
return 0;
}
本文介绍了使用Windows API进行文件复制(CopyFile)与移动(MoveFile)的方法,并提供了具体的C++示例代码,展示了如何将文件从一个位置复制到另一个位置及如何更改文件的位置。
109





