Reputation: 813
.model small
.data
filename db "name.txt",0
err db "error$"
.code
start:
mov ax,@data
mov ds,ax
;;file is opening
mov ah,3dh
lea dx,filename
mov al,0
int 21h
jc err1
;delete the file not working
mov ah, 41h
lea dx,filename
int 21h
mov ah,4ch
int 21h
err1: lea dx,err
mov ah,09h
int 21h
end start
I am trying to delete the file from the directory , but the code is not working , i can open and read the file but cant delete the file. Whats wrong with my code?
Upvotes: 1
Views: 483
Reputation: 10381
Probably your operating system doesn't allow to delete an open file, try close it:
HANDLER DW ? ;◄■■ VARIABLE IN DATA SEGMENT.
...
;;file is opening
mov ah,3dh
lea dx,filename
mov al,0
int 21h
jc err1
MOV HANDLER, AX ;◄■■ PRESERVE FILE HANDLER.
;CLOSE FILE.
MOV AH, 3EH ;◄■■
MOV BX, HANDLER ;◄■■ HANDLER OF FILE TO CLOSE.
INT 21H
;delete the file NOW IS working
mov ah, 41h
lea dx,filename
int 21h
Upvotes: 3