1. unlink and rename for Euphoria

Coming from a UNIX and C background I'm very much at home with Euphoria's
open, getc, gets, flush, close etc. file I/O functions.  I do, however, miss
the presence of unlink and rename to remove files and rename files
respectively.

One way round this is to use the system call in a fashion similar to:

    system("DEL FILENAME.TXT", 0)
    system("RENAME FILE1.TXT FILE2.TXT", 0)

but I think this isn't ideal for two reasons.  The first is that a "DOS box"
pops up for each system call (at least on Win95 and WinNT platforms - if
there is a way to suppress this please enlighten me).  The second is that if
your running on Linux your going to have to say:

    system("rm filename.txt", 0)
    system("mv file1.txt file2.txt", 0)

I agree that we can make use of the platform() function to get round this
sort of thing but again I feel we are straying down the "isn't ideal" road.

A search of the archives led me to a post which enables an unlink function
to be coded with the help of the win32lib.ew library as follows:

=========== START CODE ============
include win32lib.ew

procedure unlink(sequence filespec)

  integer  filehandle
  atom     file
  integer  exit_code

  filehandle = open(filespec, "r")

  if filehandle = -1 then
    return
  end if

  close(filehandle)

  file = allocate_string(filespec)

  exit_code = c_func(linkFunc(kernel32, "DeleteFileA", {C_POINTER}, C_INT),
{file})

  free(file)

end procedure
============ END CODE =============

I suspect a rename function could be put together in a similar fashion.

Personally I'd like to see the following:

1) Have unlink and rename built into the standard library.

2) Have an include file providing a unlink and rename function.

With Rob being so busy on the compiler option 1 doesn't seem fair smile

Option 2 sounds better.  My questions...

Has anyone done this *without* requiring the win32lib.ew library?

What name would you suggest for the include file containing unlink and
rename?  My UNIX and C background suggests "eustd.e" (a hack from "unistd.h"
smile but I sure something better could be suggested.

Thanks for listening.

Regards,

Andy Cranston.

new topic     » topic index » view message » categorize

2. Re: unlink and rename for Euphoria

As long as you are working in a win32 environment, you *can* use kernel32.dll
functions without using Win32lib. Check out the Win32 file functions by
Jeffrey Fielding in the EU archives. "Wrapping" MoveFileEx() in a similar
fashion shouldn't be that difficult for a more versatile 'rename' function.
Wolf

> A search of the archives led me to a post which enables an unlink function
> to be coded with the help of the win32lib.ew library as follows:

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

Search



Quick Links

User menu

Not signed in.

Misc Menu