Renames a file and/or moves its directory entry to a different directory on the same disk. In MS-DOS version 3.0 and later, this function can also be used to rename directories.
Call with:
AH = 56H
DS:DX = segment:offset of current ASCIIZ pathname
ES:DI = segment:offset of new ASCIIZ pathname
Returns:
If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Notes:
The function fails if:
any element of the pathname does not exist.
a file with the new pathname already exists.
the current pathname specification contains a different disk drive than does the new pathname.
the file is being moved to the root directory, and the root directory is full.
[3.0+] the program is running on a network and the user has insufficient access rights to either the existing file or the new directory.
The * and ? wildcard characters are not allowed in either the current or new pathname specifications.
Example:
Change the name of the file MYFILE.DAT in the directory \MYDIR on drive C to MYTEXT.DAT. At the same time, move the file to the directory \SYSTEM on the same drive.
oldname db 'C:\MYDIR\MYFILE.DAT',0
newname db 'C:\SYSTEM\MYTEXT.DAT',0
.
.
.
mov ah,56h ; function number
mov dx,seg oldname ; old filename address
mov ds,dx
mov dx,offset oldname
mov di,seg newname ; new filename address
mov es,di
mov di,offset newname
int 21h ; transfer to MS-DOS
jc error ; jump if rename failed
.
.
.