CopyFile實(shí)現(xiàn)文件的復(fù)制。函數(shù)原型參考MSDN。這個(gè)例子是把自己拷貝到系統(tǒng)目錄下,并且換一個(gè)名字:
1 bool CopyToSysDir()
2 {
3 bool bResult = false;
4 const TCHAR* szExeName = L"test.exe";
5 TCHAR szDestPath[MAX_PATH];
6 TCHAR szSelfPath[MAX_PATH]={0};
7 GetModuleFileName(NULL,szSelfPath,sizeof(szSelfPath));
8 GetSystemDirectory(szDestPath,MAX_PATH);
9 lstrcat(szDestPath,L"\\");
10 lstrcat(szDestPath,szExeName);
11 if(!CopyFile(szSelfPath,szDestPath,FALSE))
12 {
13 cout << "copy failed" << endl;
14 bResult = false;
15 }
16 else
17 {
18 cout << "copy success" << endl;
19 bResult = true;
20 }
21 return bResult;
22 }
|
posted on 2010-02-27 17:23
郭小帥 閱讀(482)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
API