1. Untested File Size Function

I've heard a demand for a function (I assume one wants a function) that
returns the size of a file.  Well, this is my first function, and since i=
ts
late, it will go untested.

include file.e
global function file_size(sequence path)
    integer file_i, seek_success
    file_i =3D open(path, "rb)
    seek_success =3D seek(file_i, -1)
    return where(file_i)
    close file_i
end function

I am convinced that for simple things like this, that one should define
one's own function rather than try to get all of Euphoria changed.  That =
is
what user-defined functions are for.  (At the same token, however, it
possibly wouldn't be hard for Bob to put this into the Euphoria standard
release.)

--Alan
  =

new topic     » topic index » view message » categorize

2. Re: Untested File Size Function

>include file.e
>global function file_size(sequence path)
>    integer file_i, seek_success
>    file_i = open(path, "rb)
>    seek_success = seek(file_i, -1)
>    return where(file_i)
>    close file_i
>end function


   This can be done through dir () as well, can't it ? (I mean, file-size,
date, attributes, etc.)
    I think that will be a lot cleaner, since we don't have to open it, we
can't avoid share errors, maximum open file limits, etc.
    The file size function a few people were requestion was regarding the
files they already opened. And then dos () will not return the right file
size. Euphoria cashes I/O for speed.

    -- Will return the file_size of an open handle, or -1 if it's a
streaming only device.
    -- It will not alter the position within the file. Thuis, it will not
break any I/O code when used.
    function file_size (integer fhandle)
    integer pos, s
        pos = where (fhandle)
        s = seek (fhandle, -1)
        if s then
            return -1
        else
            s = where (fhandle)
            pos = seek (fhandle, pos)
            return s
        end if
    end function

>I am convinced that for simple things like this, that one should define
>one's own function rather than try to get all of Euphoria changed.  That is
>what user-defined functions are for.  (At the same token, however, it
>possibly wouldn't be hard for Bob to put this into the Euphoria standard
>release.)

Preciously, most things can be done through the use of routines.

Ralf.

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

3. Re: Untested File Size Function

Ralf,

You just hit on an idea.  However, upon cursory inspection, I found that
you would have to do more tinkering.  Dir() returns a sequence of
sequences, and you'd have to find which file is the file you want.

--Alan
 =

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

Search



Quick Links

User menu

Not signed in.

Misc Menu