1. It seems simple...

I'm trying to open a binary file for read only, go to the last 128 bytes in
the file, and read that string. Seems simple, right? I'm at the point where
I can't find an equivalent Euphoria routine that I'd use if I were writing
this in VB. In VB, I'd use -- FileLen(FileName) - 127 -- to do what I'm
trying. I tried to use get_bytes, but to no avail. Can anybody send me a
snippet of code that'll do what I need?

Seek() would work fine for moving the placement of the next reading to 128
bytes from the end of the file, but getting the actual length of the file is
where I'm stuck.

Thanks,
Brian

new topic     » topic index » view message » categorize

2. Re: It seems simple...

>From library.doc

Seek (move) to any byte position in the file fn or to the end of
              file if i2 is -1. For each open file there is a current byt=
e
              position that is updated as a result of I/O operations on t=
he
              file. The initial file position is 0 for files opened for r=
ead,
              write or update. The initial position is the end of file fo=
r
              files opened for append. The value returned by seek() is 0 =
if the
              seek was successful, and non-zero if it was unsuccessful. I=
t is
              possible to seek past the end of a file. In this case undef=
ined
              bytes will be added to the file to make it long enough for =
the
              seek.

=AF assumes fn is already defined and opened
atom fpos
fpos =3D seek(fn,-1)
if fpos=3D0 then
  fpos=3Dwhere(fn)
  fpos=3Dseek(fn,fpos-127)
end if
=AF assuming both seeks were successful, you are now 128 bytes prior to t=
he end of the file.

Michael J. Sabal


>>> impee3 at EXCITE.COM 12/13/00 01:11PM >>>
I'm trying to open a binary file for read only, go to the last 128 bytes =
in
the file, and read that string. Seems simple, right? I'm at the point whe=
re
I can't find an equivalent Euphoria routine that I'd use if I were writin=
g
this in VB. In VB, I'd use -- FileLen(FileName) - 127 -- to do what I'm
trying. I tried to use get_bytes, but to no avail. Can anybody send me a
snippet of code that'll do what I need?

Seek() would work fine for moving the placement of the next reading to 12=
8
bytes from the end of the file, but getting the actual length of the file=
 is
where I'm stuck.

Thanks,
Brian

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

3. Re: It seems simple...

Hey, guess I must of missed this one so when I saw the last post
I thought I'd put my pennies worth in.

--Begin Code

include get.e
include file.e

object junk
integer fn, file_length, pointer
sequence seq

 fn = open(filename , "rb")
 junk=seek(fn,-1)
 file_length=where(fn)
 pointer = file_length - 128
 junk=seek(fn,pointer)

 seq=repeat(0,128)

 for x = 1 to 128 do
     seq[x] = getc(fn)
 end for

-- End Code

If this wont work, somebody please let me know.

BEWARE UNTESTED CODE
euman at bellsouth.net

----- Original Message -----
From: Brian <impee3 at EXCITE.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Wednesday, December 13, 2000 1:11 PM
Subject: It seems simple...


> I'm trying to open a binary file for read only, go to the last 128 bytes
in
> the file, and read that string. Seems simple, right? I'm at the point
where
> I can't find an equivalent Euphoria routine that I'd use if I were writing
> this in VB. In VB, I'd use -- FileLen(FileName) - 127 -- to do what I'm
> trying. I tried to use get_bytes, but to no avail. Can anybody send me a
> snippet of code that'll do what I need?
>
> Seek() would work fine for moving the placement of the next reading to 128
> bytes from the end of the file, but getting the actual length of the file
is
> where I'm stuck.
>
> Thanks,
> Brian
>

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

4. Re: It seems simple...

i know this sounds bad and potentially cumbersome (especially for big
files), but I'd say just read the whole file and take the last 128
characters...oh well.



----------
Mike Hurley
EMail: mikehurley.1 at netzero.net
Web: http://members.xoom.com/MikesEuWeb/

_______________________________________________
Why pay for something you could get for free?
NetZero provides FREE Internet Access and Email
http://www.netzero.net/download/index.html

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

Search



Quick Links

User menu

Not signed in.

Misc Menu