pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


MoveFileExA() test
Posted by Anonymous on Tue 22nd Jul 2025 09:43
raw | new post

  1. #include <stdio.h>    
  2. #include <windows.h>  
  3. #include <stdlib.h>  
  4.  
  5. int main(int argc, char *argv[]) {
  6.     if (argc != 3) {
  7.         fprintf(stderr, "Usage: %s <source_path> <destination_path>\n", argv[0]);
  8.         return EXIT_FAILURE;
  9.     }
  10.  
  11.     LPCSTR sourcePath = argv[1];
  12.     LPCSTR destinationPath = argv[2];
  13.  
  14.     printf("Attempting to move '%s' to '%s'...\n", sourcePath, destinationPath);
  15.  
  16.     if (MoveFileExA(sourcePath, destinationPath, MOVEFILE_REPLACE_EXISTING)) {
  17.         printf("File moved successfully!\n");
  18.         return EXIT_SUCCESS;
  19.     } else {
  20.         DWORD error = GetLastError();
  21.         fprintf(stderr, "Error moving file. Error code: %ld\n", (long)error);
  22.         if (error == ERROR_FILE_NOT_FOUND) {
  23.             fprintf(stderr, "Reason: The specified source file was not found.\n");
  24.         } else if (error == ERROR_ACCESS_DENIED) {
  25.             fprintf(stderr, "Reason: Access denied. Check file permissions or if the file is in use.\n");
  26.         } else if (error == ERROR_ALREADY_EXISTS) {
  27.             fprintf(stderr, "Reason: The destination file already exists and MOVEFILE_REPLACE_EXISTING was not specified.\n");
  28.         }
  29.         return EXIT_FAILURE;
  30.     }
  31. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at