mov dx, seg OldName
mov ds, dx
mov dx, offset OldName ;ds:dx points to old file or directory name
mov di, seg NewName
mov es, di
mov di, offset NewName ;es:di points to new file or directory name
mov ah, 56h ;Rename File
int 21h
jc error_handler ;carry set means error
Rename File (Function 56h) renames or moves a file or directory by changing its directory entry.
OldName
Points to a zero-terminated ASCII string that specifies the file or directory to rename or move. The name must be a valid MS-DOS filename or directory name and cannot include wildcards.
NewName
Points to a zero-terminated ASCII string that specifies the new name for the file or directory. The name must be a valid MS-DOS filename or directory name and cannot include wildcards.
If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:
Value | Name |
0002h | ERROR_FILE_NOT_FOUND |
0003h | ERROR_PATH_NOT_FOUND |
0005h | ERROR_ACCESS_DENIED |
0011h | ERROR_NOT_SAME_DEVICE |
Open files or directories must be closed before they are moved or renamed with this function.
A program can use this function to move a file or directory by specifying different paths for the OldName and NewName parameters and keeping the filename or directory name the same. This function cannot be used to move files or directories from one disk drive to another; however, both the old and new names must specify the same drive either explicitly or by default.
If the specified file is on a network drive, the function renames the file only if network grants create and delete access to the drive or directory.
Function 17h Rename File with FCB