Re: Untested File Size Function

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

>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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu