1. deleting files and accessing directory tree

hey, i feel like an idiot for asking, but i'm trying to delete files from within my Eu code on win. i can't find a way of doing this. So I figure there is some low level way of achieving this, since i can't get it done using system() or system_exec(). Thanks.

new topic     » topic index » view message » categorize

2. Re: deleting files and accessing directory tree

robsteele said...

hey, i feel like an idiot for asking, but i'm trying to delete files from within my Eu code on win. i can't find a way of doing this. So I figure there is some low level way of achieving this, since i can't get it done using system() or system_exec(). Thanks.

On Windows, I just did this and it worked:

system("del logfile.txt",2) 
new topic     » goto parent     » topic index » view message » categorize

3. Re: deleting files and accessing directory tree

i'm 3.1.1 and it just says File not found. I just figured out that it won't do this for filenames with extensions > 3 letters, it deprecates it to 3. So if you have a file test.html and test.htm, and try to delete test.html it will delete the latter. Thanks for the help though.

new topic     » goto parent     » topic index » view message » categorize

4. Re: deleting files and accessing directory tree

We would need a function that return the 8.3 path for any long filename path.

shortpath("c:\Mis Documentos\Mi pagina.html") returns "c:\misdoc~1\mipagi~1.htm"

new topic     » goto parent     » topic index » view message » categorize

5. Re: deleting files and accessing directory tree

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í

new topic     » goto parent     » topic index » view message » categorize

6. Re: deleting files and accessing directory tree

poke(pname+len,0) 

should be

poke(pname+length(name),0) 

Sorry, I miss the windows interpreter ;)

new topic     » goto parent     » topic index » view message » categorize

7. Re: deleting files and accessing directory tree

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 message » categorize

8. Re: deleting files and accessing directory tree

ghaberek said...

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

Thanks for the remainder, I guess I got used to poke around smile

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu