码迷,mamicode.com
首页 > 编程语言 > 详细

C++ CopyFile()

时间:2018-01-06 00:34:35      阅读:430      评论:0      收藏:0      [点我收藏+]

标签:系统   windows   ready   rect   window   tor   int   mmu   copy file   

关于CopyFile function,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/aa363851(v=vs.85).aspx

 

IDE: Code::Blocks 16.01

操作系统:Windows 7 x64

 1 #include <windows.h>
 2 #include <stdio.h>
 3 
 4 int main()
 5 {
 6     DWORD dwError;
 7 
 8     if(CopyFile("H:\\C++\\NewDirectory\\file.txt", "H:\\C++\\NewDirectory\\del.bat", FALSE)) {
 9         printf("Copy file succeeds. \n");
10     }
11     else {
12         dwError = GetLastError();
13         switch(dwError) {
14         case ERROR_FILE_NOT_FOUND:
15             printf("The source file does not exist. \n");
16             printf("Error: %ld \n", dwError);
17             break;
18         default:
19             printf("The new file already exists. \n");
20             printf("Error: %ld \n", dwError);
21             break;
22         }
23     }
24 
25     return 0;
26 }

 

IDE: Microsoft Visual Studio Community 2017 15.5.2

操作系统:Windows 7 x64

 1 #include "stdafx.h"    /* IDE自行创建的 */
 2 
 3 #include <windows.h>
 4 
 5 int main(int argc, char **argv)
 6 {
 7     DWORD dwError;
 8 
 9     if (CopyFile(L"H:\\C++\\NewDirectory\\file.txt", L"H:\\C++\\NewDirectory\\del.bat", FALSE)) {
10         printf("Copy file succeeds. \n");
11     }
12     else {
13         dwError = GetLastError();
14         switch (dwError) {
15         case ERROR_FILE_NOT_FOUND:
16             printf("The source file does not exist. \n");
17             printf("Error: %ld \n", dwError);
18             break;
19         default:
20             printf("The new file already exists. \n");
21             printf("Error: %ld \n", dwError);
22             break;
23         }
24     }
25 
26     getchar();
27 
28     return 0;
29 }

 

C++ CopyFile()

标签:系统   windows   ready   rect   window   tor   int   mmu   copy file   

原文地址:https://www.cnblogs.com/Satu/p/8207304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!