Re: Deleting a file
--=====================_862467637==_
At 19:09 97-04-28 -0400, Daniel Berstein wrote:
>I need to delete a file, but don't want to use the system() function,
>cause it has to be "transparent" to the user. So I got this bright
>idea of using DOS interrupts (#21). At the end is the code I used, but
>it doesn't work... I keep getting DOS error 2 (file not found) and
>5 (access denied). Can anyone tell me what is wrong? Is there any
>other way to that?
>I also needed to copy a file but I solve that with a loop of getc() and
>puts() until an EOF.. is there another eficient way?
>
>Thanks.
>
>
>-------------CUT HERE--------------
>
>-- SYS_DEL()
>-- Uses DOS INT #21, service #41 to delete a file given an ASCIIZ filename
>-- Returns 1 if succesfull, else return 0 and displays DOS error code
>
>-- INT reference: HelpPC 2.1
>function sys_del(sequence filename)
> sequence reg_list
> integer buff
>
> buff = allocate_low(length(filename)+1)
> poke(buff,filename)
> poke(buff+length(filename),0)
>
> reg_list = repeat(0,10)
>
> reg_list[REG_AX] = #4100
> reg_list[REG_DS] = floor(buff/16)
> reg_list[REG_DX] = remainder(buff,16)
>
> reg_list = dos_interrupt(#21,reg_list)
> free_low(buff)
>
> if remainder(reg_list[REG_FLAGS],2) != 0 then
> puts(1, "DOS error number :")
> print(1,reg_list[REG_AX])
> puts(1,"\n")
> return 0
> else
> return 1
> end if
>end function
>
>--------END OF CODE--------
I tested it on my computer without any problem.
I attached copy.ex which use dos interrupt #21 to copy a file. You need
doswrap.e
to use it. If you don't have it you can find it on Euphoria Official home
page or
drop me an e-mail I'll send it to you.
--=====================_862467637==_
-- copying file demo.
include doswrap.e
constant BUFF_SIZE = power(2,15)
function CopyFile(sequence Source, sequence Dest)
atom buffer
integer FSrc, FDest, NbRead, junk
FSrc = DosOpen(Source,READ)
if FSrc = -1 then
return 0
end if
FDest = DosCreate(Dest,0)
if FDest = -1 then
return 0
end if
buffer = allocate_low(BUFF_SIZE)
if buffer = 0 then
return 0
end if
NbRead = BlockRead(FSrc,buffer,BUFF_SIZE)
while NbRead > 0 do
if BlockWrite(FDest,buffer,NbRead) = -1 then
junk = DosClose(FSrc)
junk = DosClose(FDest)
free_low(buffer)
return 0
end if
NbRead = BlockRead(FSrc,buffer,BUFF_SIZE)
end while
junk = DosClose(FSrc)
junk = DosClose(FDest)
free_low(buffer)
return 1
end function
--=====================_862467637==_
Jacques Deschenes
Baie-Comeau, Quebec
Canada
desja at quebectel.com
--=====================_862467637==_--
|
Not Categorized, Please Help
|
|