- #include <stdio.h>
- #include <windows.h>
- #include <stdlib.h>
- int main(int argc, char *argv[]) {
- if (argc != 3) {
- return EXIT_FAILURE;
- }
- LPCSTR sourcePath = argv[1];
- LPCSTR destinationPath = argv[2];
- if (MoveFileExA(sourcePath, destinationPath, MOVEFILE_REPLACE_EXISTING)) {
- return EXIT_SUCCESS;
- } else {
- DWORD error = GetLastError();
- if (error == ERROR_FILE_NOT_FOUND) {
- } else if (error == ERROR_ACCESS_DENIED) {
- } else if (error == ERROR_ALREADY_EXISTS) {
- fprintf(stderr, "Reason: The destination file already exists and MOVEFILE_REPLACE_EXISTING was not specified.\n");
- }
- return EXIT_FAILURE;
- }
- }
MoveFileExA() test
Posted by Anonymous on Tue 22nd Jul 2025 09:43
raw | new post
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.