Int 21H [2.0] Function 41H (65) Delete file

Deletes a file from the specified or default disk and directory.

Call with:

AH = 41H

DS:DX = segment:offset of ASCIIZ pathname

Returns:

If function successful

Carry flag = clear

If function unsuccessful

Carry flag = set

AX = error code

Notes:

This function deletes a file by replacing the first character of its filename in the directory with the character e (E5H) and marking the file's clusters as "free" in the disk's file allocation table. The actual data stored in those clusters is not overwritten.

Only one file at a time may be deleted with this function. Unlike the FCB-related Delete File function (Int 21H Function 13H), the * and ? wildcard characters are not allowed in the file specification.

The function fails if:

any element of the pathname does not exist.

the designated file exists but has the read-only attribute. (Int 21H Function 43H can be used to examine and modify a file's attribute before attempting to delete it.)

[3.0+] the program is running on a network, and the user running the program has insufficient access rights.

Example:

Delete the file named MYFILE.DAT from the directory \MYDIR on drive C.

fname db 'C:\MYDIR\MYFILE.DAT',0

.

.

.

mov ah,41h ; function number

mov dx,seg fname ; filename address

mov ds,dx

mov dx,offset fname

int 21h ; transfer to MS-DOS

jc error ; jump if delete failed

.

.

.