1. deleting files and accessing directory tree
- Posted by robsteele Oct 19, 2008
- 1045 views
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.
2. Re: deleting files and accessing directory tree
- Posted by euphoric (admin) Oct 19, 2008
- 1063 views
- Last edited Oct 20, 2008
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)
3. Re: deleting files and accessing directory tree
- Posted by robsteele Oct 20, 2008
- 1075 views
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.
4. Re: deleting files and accessing directory tree
- Posted by achury Oct 21, 2008
- 1075 views
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"
5. Re: deleting files and accessing directory tree
- Posted by gbonvehi Oct 22, 2008
- 1057 views
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Ã
6. Re: deleting files and accessing directory tree
- Posted by gbonvehi Oct 22, 2008
- 1028 views
poke(pname+len,0)
should be
poke(pname+length(name),0)
Sorry, I miss the windows interpreter ;)
7. Re: deleting files and accessing directory tree
- Posted by ghaberek (admin) Oct 23, 2008
- 1124 views
- Last edited Oct 24, 2008
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.
-Greg
8. Re: deleting files and accessing directory tree
- Posted by gbonvehi Oct 24, 2008
- 1025 views
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.
-Greg
Thanks for the remainder, I guess I got used to poke around