Windows API one-day training (57) CopyFile and MoveFile Functions

Source: Internet
Author: User
In the information society, sharing information is very important. For example, if you have a good photo, copy it to a friend to share it. Or you need to copy files to different directories when writing important data and backing up them from time to time. In this way, you need to use the CopyFile function to copy an object, which can copy one file and more. I am developing a data collection software, because this software can be used by different users, the user told me that there is such a demand, that is, the data of different users is moved to different directories, so that they can easily manage the data and find their useful files in thousands of files, instead of mixing it with other files, you need to move the file to the corresponding directory after the collected data is completed. In this way, you need to use the MoveFile function to move the file. The CopyFile and MoveFile functions are declared as follows: extract (_ in LPCSTR lpExistingFileName, _ in lpNewFileName, _ in BOOL bFailIfExists); extract (_ in LPCWSTR lpExistingFileName, _ in LPCWSTR lpNewFileName, _ in BOOL bFailIfExists); # ifdef UNICODE # define CopyFile CopyFileW # else # define CopyFile CopyFileA # endif //! UNICODE encode (_ in lpstr lpExistingFileName, _ in lpstr lpNewFileName); WINBASEAPIBOOLWINAPIMoveFileW (_ in LPCWSTR lpExistingFileName, _ in LPCWSTR lpNewFileName ); # ifdef UNICODE # define MoveFile MoveFileW # else # define MoveFile MoveFileA # endif //! An example of UNICODE function calling is as follows: #001 // copy and move a file. #002 // Cai junsheng 2007/10/24 QQ: 9073204 Shenzhen #003 void CopyAndMoveFile (void) #004 {# 005 // copy the file. #006 BOOL bRes =: CopyFile (_ T ("CreateFileDemo.txt"), #007 _ T ("CreateFileDemo_New.txt"), FALSE); #008 if (bRes) #009 {#010 // #011 OutputDebugString (_ T ("file copied successfully! \ R \ n "); #012} #013 #014 // move the file. #015 bRes =: MoveFile (_ T ("CreateFileDemo.txt"), #016 _ T (". \ Debug \ CreateFileDemo.txt "); #017 if (bRes) #018 {#019 // #020 OutputDebugString (_ T (" file moved successfully! \ R \ n "); #021} #022} #023
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.