I am trying to start simply by writing a program that deletes a file in the same folder as the program but when I run it i get "Illegal Path". Here's the code:
masm
model small
.data
filename db "my_file.txt"
point_fname dd filename
.stack 256
.code
main:
mov ax,@data
mov ds,ax
lds dx,point_fname
mov ax,41h
int 21h
jc exit
nop
exit:
mov ax,4c00h
int 21h
end main
Shouldn't it be searching where the .ASM file of the program is or i should give the path name?
Also I am not sure how should i give the path to DX (as far as i am aware it should be set there) . Should i write it in the filename?
A few things you need to look at.
As per Ralf Brown's excellent interrupt list, deleting a file is done with int21/ah=41. By setting ax
to 0041
, you're setting ah
to zero which is the "terminate program" function. You need:
mov ah, 41h
Secondly, the filename is meant to be an ASCIZ, meaning it should be terminated by a zero byte:
filename db "my_file.txt", 0
Thirdly, you appear to have some unneeded indirection in there (a la point_fname
). The ds:dx
register pair should point directly at the file name and you should be able to do that without the extra data item.
You're stretching my memory here but I think you would ditch the point_fname
and lds
call and instead just load the offset of the filename directly into dx
with something like:
mov dx, offset filename
The indirection-with-lds method will probably work, but it seems an unnecessary complication.
You may also want to be careful that this sort of stuff still works in modern versions of Windows (it may, or it may not).
Microsoft is a big believer in backward compatibility but this stuff was introduced in MSDOS 2 and may not support such wondrous new thing as filenames beyond the 8.3 limit, or NTFS :-)
If you're running in DosBox or under a VM running Windows 98 or lesser, you should be fine, but I'd be at least a little circumspect about functionality beyond that.