Re: deleting files and accessing directory tree

new topic     » goto parent     » topic index » view thread      » older message » newer message
gbonvehi said...

You can include this code in your program and call deleteFile function which wraps Win32 API's DeleteFile function.

WARNING: Untested code (I don't have Windows here)! You can find a similar code in Win32Lib IIRC and/or Euphoria's Archives ( http://www.rapideuphoria.com/archive.htm )

include machine.e 
include dll.e 
 
constant 
    wKernel32           = open_dll("kernel32.dll"), 
    wDeleteFile         = define_c_func(wKernel32, "DeleteFileA", {C_POINTER}, C_LONG) 
 
function deleteFile(sequence name) 
	atom pname 
    atom retval 
	pname = allocate(length(name)+1) 
	poke(pname, name) 
	poke(pname+len,0) 
	retval = c_func(wDeleteFile,{pname}) 
	free(pname) 
	return retval 
end function 
 
if wKernel32 = 0 then 
    puts(1,"Error in open_dll(\"kernel32.dll\")\n") 
    abort(1) 
end if 

As stated by MSDN, deleteFile will return 0 if it fails. Link: http://msdn.microsoft.com/en-us/library/aa363915(VS.85).aspx

Hope this helps, Guillermo Bonvehí

You could just make that...

function deleteFile( sequence name ) 
 
	atom pname, retval 
 
	pname = allocate_string( name ) 
	retval = c_func( wDeleteFile, {pname} ) 
	free( pname ) 
 
	return retval 
end function 

Which would work equally as well, with a few less lines of code. We have allocate_string for a reason. blink

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu