C + + file Cut Copy Delete

Source: Internet
Author: User
When we write some programs that have destructive programs, we tend to cut and delete programs and so on.

Here is a brief explanation of the Cut copy deletion,


Copying of files

#include <Windows.h>  #include <stdio.h>    int main ()  {      DWORD GetLastError;      if (! Copyfilea ("C:\\1.txt", "F:\\1.txt", false))      {          printf_s ("file copy failed \ n");          GetLastError = GetLastError ();          return-1;      }      return 0;  }


After the operation we can find that we can move the 1.txt from the C drive to the F drive.

The following function is explained below.


CopyFile function

BOOL WINAPI CopyFile (    _in_ lpctstr lpexistingfilename,    _in_ lpctstr lpnewfilename,    _in_ bool    Bfailifexists  );

First parameter: The name of a file that exists

Second parameter: The name of a new file

Third parameter: If there is a file with the same name true then no copy is made, False is overwrite.

Return value: Success returns a non-0 number, failure returns 0, and calling GetLastError () can get an error message.

Here is the deletion code for the file

#include <Windows.h>  #include <stdio.h>    int main ()  {      DWORD GetLastError;        if (! DeleteFileA ("C:\\1.txt"))      {          GetLastError = GetLastError ();          printf_s ("c:\\1.txt delete failed");          return-1;        }      if (! DeleteFileA ("F:\\1.txt"))      {          GetLastError = GetLastError ();          printf_s ("f:\\1.txt delete failed");          return-1;      }      printf_s ("Delete succeeded \ n");          return 0;  }

DeleteFile function

BOOL WINAPI DeleteFile (    _in_ lpctstr lpfilename  );

The parameter here is the name of the file to be deleted

return value:

The success returns a non-0 number, the failure returns 0, and the call to GetLastError () gets the error message.



Here is the cut of the file

#include <Windows.h>  #include <stdio.h>    int main ()  {      if (! Movefilea ("C:\\1.txt", "F:\\1.txt"))      {          DWORD GetLastError;          Getlasterror=getlasterror ();          printf_s ("copy failed");          return-1;      }      printf_s ("Copy succeeded \ n");      return 0;  }

The parameters and return values of the function are similar to the one above, and are not explained here.

The above is the C + + file Cut Copy deleted content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.