1. delete bytes?

I have a text file open and I want to write a few words after the 25th byte and
delete the rest. What should I do?

include file.e

integer fn, fx
fn = open("mytext.txt", "u")
fx = seek(fn, 25) 
puts(fn,"Aha!\n")
-- ... and now what?


Regards,

Salix

new topic     » topic index » view message » categorize

2. Re: delete bytes?

Salix wrote:
> 
> I have a text file open and I want to write a few words after the 25th byte
> and delete the rest. What should I do?
> 
> }}}
<eucode>

> -- ... and now what?
> </eucode>
{{{

> 
> Regards,
> 
> Salix



 include file.e
 
 integer fn, fx
 fn = open("mytext.txt", "u")
 fx = seek(fn, 25) 
 puts(fn,"Aha!\n") 
 puts(fn,0)

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

3. Re: delete bytes?

Evan Marshall wrote:
> 
> Salix wrote:
> > 
> > I have a text file open and I want to write a few words after the 25th byte
> > and delete the rest. What should I do?
> >  
> 
>  include file.e
>  
>  integer fn, fx
>  fn = open("mytext.txt", "u")
>  fx = seek(fn, 25) 
>  puts(fn,"Aha!\n") 
>  puts(fn,0)

The puts(fn,0) doesn't seem to delete everything if there are \n characters in
the text. sad

Regards,

Salix

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

4. Re: delete bytes?

Salix wrote:
> 
> Evan Marshall wrote:
> > 
> > Salix wrote:
> > > 
> > > I have a text file open and I want to write a few words after the 25th
> > > byte
> > > and delete the rest. What should I do?
> > >  
> > 
> >  include file.e
> >  
> >  integer fn, fx
> >  fn = open("mytext.txt", "u")
> >  fx = seek(fn, 25) 
> >  puts(fn,"Aha!\n") 
> >  puts(fn,0)
> 
> The puts(fn,0) doesn't seem to delete everything if there are \n characters
> in the text. sad
> 
> Regards,
> 
Salix:

  Try This:

include file.e

integer fn, fx fn = open("mytext.txt", "u") fx = seek(fn, 25) puts(fn,"Aha!\n") print(fn,26) ctl-Z or 26 #1A close(fn) }}}



Bernie

My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API

Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan }}}

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

5. Re: delete bytes?

Bernie Ryan wrote:
> 
<snip>
> 
>   Try This:
> 
> }}}
<eucode>
> include file.e
> 
> integer fn, fx
> fn = open("mytext.txt", "u")
> fx = seek(fn, 25) 
> puts(fn,"Aha!")
> print(fn,26) -- ctl-Z or 26 #1A
> close(fn)
> }}}
<eucode> 
> 
> Bernie

That doesn't seem to work, either.  It just replaces the 26th through the
30th bytes.

abcdefghijklmnopqrstuvwxyz123456789 becomes

abcdefghijklmnopqrstuvwxyAha!56789

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

6. Re: delete bytes?

Oops,

include file.e
 
 integer fn, fx
 fn = open("mytext.txt", "u")
 fx = seek(fn, 25) 
 puts(fn,"Aha!\n")
 print(fn,26) -- ctl-Z or 26 #1A
 close(fn)


actually makes

abcdefghijklmnopqrstuvwxyz12346789 become

abcdefghijklmnopqrstuvwxyAha!
26798

which seems really strange.

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

7. Re: delete bytes?

Salix wrote:

> I have a text file open and I want to write a few words after the 25th byte
> and delete the rest. What should I do?
> 
> }}}
<eucode>
> include file.e
> 
> integer fn, fx
> fn = open("mytext.txt", "u")
> fx = seek(fn, 25)
> puts(fn,"Aha!\n")
> -- ... and now what?
> </eucode>
{{{


In BASIC it was/is possible to clip a file by writing zero bytes (not
a byte with value 0) at the desired end of the file. For details see
this book, now free in electronic form:
     http://www.ethanwiner.com/WINER.ZIP
Then in "Chap11.txt", look for the procedure ClipFile().

Some time ago I had tried to do the same with Euphoria, using
     puts(fn, "")
Unfortunately, without success.

Maybe this is possible with Euphoria by calling a DOS interrupt or
a Windows/Linux API function.

Regards,
   Juergen

-- 
Have you read a good program lately?

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

8. Re: delete bytes?

> I have a text file open and I want to write a few words after the 25th by=
te and delete the rest. What should I do?

its only 25 bytes, why not do this?

include get.e
include file.e

integer fn
sequence bytes

-- open file for reading
fn = open("mytext.txt", "r")
-- buffer the data
bytes = get_bytes(fn, 25)
-- close file
close(fn)

-- open file for writing
fn = open("mytext.txt", "w")
-- output buffer
puts(fn, bytes)
-- output our data
puts(fn,"Aha!\n")
-- close the file
close(fn)


~Greg

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

9. Re: delete bytes?

You could use interrupt 13h to sector read the disk's FAT(s), look for the
file entry and modify the file's size before sector writting back to disk.

Search www for 'Creating A Bootdisk' or 'Modifying the VFAT', I've seen a
few good examples out there in the past.

Regards,
    Hayden

Q. How many programmers doe's it take to change a lightbulb?
A. None, its a hardware problem!

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

10. Re: delete bytes?

Greg Haberek wrote:
> 
> > I have a text file open and I want to write a few words after the 25th by=
> te and delete the rest. What should I do?
> 
> its only 25 bytes, why not do this?
> 
> ... 

Because in reality it is not 25 bytes but can be anything (including 837 252
938)
depending on the situation. I just tried to "strip down" the problem. 

My first thought was to finish the writting with puts(fn,EOF) but obviously
didn't
worked. :-] Following Hayden's and Jürgen's suggestions I try to find some
examples
in other languages on the web. (But frankly, I do not expect too much from this 
knowing my programming knowledge...)

More tips and advices are welcome!

Regards,

Salix

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

11. Re: delete bytes?

Salix wrote:
> 
> Greg Haberek wrote:
> > 
> > > I have a text file open and I want to write a few words after the 25th by=
> > te and delete the rest. What should I do?

> More tips and advices are welcome!

** Open the input file with "r".
** Create a new empty output file with "w".
** Copy the bytes you want from the input file to the output file.
** Add the 'suffix' stuff to the output file.
** Close both files.
** Delete or rename the input file.
** Rename the output file to the input file name.


There is no built-in function to delete or rename files but you can use the
system command to do these type of things.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

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

12. Re: delete bytes?

Hayden McKay wrote:
> 
> 
> You could use interrupt 13h to sector read the disk's FAT(s), look for the
> file entry and modify the file's size before sector writting back to disk.
> 
> Search www for 'Creating A Bootdisk' or 'Modifying the VFAT', I've seen a
> few good examples out there in the past.
> 
> Regards,
>     Hayden
> 
> Q. How many programmers doe's it take to change a lightbulb?
> A. None, its a hardware problem!

I don't know about you but I rarely "get it right" the first time I write a
program or routine.  This would be a rather risky approach.

The only safe thing I can think of is to re-write the file and let the OS take
care of it.  Isn't that why we have operating systems?

-- Brian

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

Search



Quick Links

User menu

Not signed in.

Misc Menu