My bet is that KILL probably uses the same MS-DOS function, or one of the others.
This program works in QBASIC 1.1 on Windows XP 32 bit. It creates a file in the current folder called "trash.tmp", then deletes it.
'public domain, april 2011, michael calkins
CONST file = "trash.tmp"
DIM filename AS STRING
DIM result AS LONG
DIM t AS STRING
DIM i AS INTEGER
CONST codelen = 48
DIM code AS STRING * codelen
t = "5589E51E8B560C8EDA8B5E0A8B5702B441CD218B56088EDA8B5E06720B6631C0"
t = t + "6689071F5DCA0800660D0000FFFFEBF0"
FOR i = 0 TO codelen - 1
MID$(code, i + 1, 1) = CHR$(VAL("&h" + MID$(t, i + i + 1, 2)))
OPEN file FOR APPEND AS 1
PRINT #1, "I am doomed! :-("
PRINT "now you see it:"
SHELL "dir " + file
filename = file + CHR$(0)
DEF SEG = VARSEG(code)
CALL absolute(SEG filename, SEG result, VARPTR(code))
IF result THEN
PRINT "oops. error: 0x"; HEX$(result AND &HFFFF&)
PRINT "now you don't:"
SHELL "dir " + file
;public domain, april 2011, michael calkins
;Qbasic Call Absolute function to delete a file.
;Call with: a far pointer to a QBASIC variable length string, and a far pointer to a LONG.
; QBASIC string should contain a null terminated string with the name of the file to delete.
; The LONG will be used to return the result:
; if success: 0x0.
; if failure: high word: 0xffff, low word: error code given by DOS.
mov dx,[bp+0xc] ;segment of string descriptor
mov bx,[bp+0xa] ;offset of string descriptor
mov dx,[bx+0x2] ;offset of actual string
mov dx,[bp+0x8] ;segment of long
mov bx,[bp+0x6] ;offset of long
With regard to the file being in use:
I did an experiment where I opened the file in notepad after creating it, but before deleting it. The deletion succeeded, as it did from Windows Explorer also. I tried it on a file that was open in another instance of QBASIC with OPEN ... LOCK WRITE ..., and it succeeded in both the program and Windows Explorer. I tried doing it on a running copy of QBASIC.EXE, and it also succeeded from the program, and from Windows Explorer. I tried doing it on a running copy of Notepad.exe, and it failed from Windows Explorer with:
"Error Deleting File or Folder
Cannot delete Copy of NOTEPAD; Access is denied.
Make sure the disk is not full or write-protected and that the file is not currently in use."
and failed in the program with code 0x5.
So, it seems to me that there is nothing inherently wrong with using MS-DOS int 0x21, function 0x41.
|Response Title||Author and Date|
|The Absolute code worked. Never seen SEG used like that???||on Apr 3|
|*SEG forces the parameter to be passed as a far pointer, instead of as a near pointer.||on Apr 3|
|* I'd like to use your demo in the QB64 WIKI if that is OK with you Michael.||on Apr 7|
|Yes||on Apr 7|
|I just wanted to document it in case it ever does||on Apr 7|
|SEG||DICK on Apr 7|
|turbo basic||DICK on Apr 7|
|Thanks for the explanation!||on Apr 7|
|*I forgot about LDS... (I've read about it, but I don't think I've used it yet.)||on Apr 8|
|*I have 4 posts here(URL)||on Apr 8|