MoveFile Function
The MoveFile function moves an existing file from one location to another.
BOOL MoveFile(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName
);
Parameters
lpExistingFileName-
A null-terminated string that specifies the current name of the file.
For more information, see the Remarks section of
MoveFileEx. lpNewFileName-
A null-terminated string that specifies the new name of the file.
For more information, see the Remarks section of
MoveFileEx.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The MoveFile function provides basic file moving capabilities. For more advanced options, such as controlling whether the move is atomic or can be rescheduled, consider using the MoveFileEx function.
If the destination file already exists, MoveFile will overwrite it. If the source and destination are on different volumes, this function will fail unless the source file is first copied and then deleted.
Error Codes
The following table lists common error codes that may be returned by GetLastError:
| Error Code | Description |
|---|---|
ERROR_FILE_NOT_FOUND |
The system cannot find the file specified. |
ERROR_PATH_NOT_FOUND |
The system cannot find the path specified. |
ERROR_ACCESS_DENIED |
Access is denied. |
ERROR_INVALID_PARAMETER |
One of the parameters is invalid. |
ERROR_DIR_NOT_EMPTY |
The directory is not empty. |
Requirements
| Client | Server |
|---|---|
| Windows 2000, Windows XP, Windows Server 2003 | Windows Server 2003 |
See Also
Note: This is a simplified overview. For comprehensive details and platform-specific behavior, consult the official Windows documentation.