mov dx, seg FileName
mov ds, dx
mov dx, offset FileName ;ds:dx points to filename
mov ah, 41h ;Delete File
int 21h
jc error_handler ;carry set means error
Delete File (Function 41h) deletes a specified file.
FileName
Points to a zero-terminated ASCII string that specifies the file to delete. This string must be a valid MS-DOS filename and cannot contain 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 values:
Value | Name |
0002h | ERROR_FILE_NOT_FOUND |
0003h | ERROR_PATH_NOT_FOUND |
0005h | ERROR_ACCESS_DENIED |
This function cannot be used to remove a directory, a volume label, or a read-only file. A program can use Set File Attributes (Function 4301h) to change the attributes of a read-only file so that the file can be deleted.
If the specified file is on a network drive, the function deletes the file only if network grants delete access to the drive or directory.
Function 3Ah Remove Directory
Function 4300h Get File Attributes
Function 4301h Set File Attributes