1. delete bytes?
- Posted by Salix <salix at freemail.hu> Mar 19, 2006
- 565 views
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
2. Re: delete bytes?
- Posted by Evan Marshall <1evan at sbcglobal.net> Mar 19, 2006
- 558 views
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)
3. Re: delete bytes?
- Posted by Salix <salix at freemail.hu> Mar 19, 2006
- 563 views
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. Regards, Salix
4. Re: delete bytes?
- Posted by Bernie Ryan <xotron at bluefrog.com> Mar 19, 2006
- 588 views
- Last edited Mar 20, 2006
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. > > 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 }}}
5. Re: delete bytes?
- Posted by Evan Marshall <1evan at sbcglobal.net> Mar 19, 2006
- 567 views
- Last edited Mar 20, 2006
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
6. Re: delete bytes?
- Posted by Evan Marshall <1evan at sbcglobal.net> Mar 19, 2006
- 555 views
- Last edited Mar 20, 2006
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.
7. Re: delete bytes?
- Posted by Juergen Luethje <j.lue at gmx.de> Mar 19, 2006
- 568 views
- Last edited Mar 20, 2006
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?
8. Re: delete bytes?
- Posted by "Greg Haberek" <ghaberek at gmail.com> Mar 20, 2006
- 564 views
> 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
9. Re: delete bytes?
- Posted by Hayden McKay <hmck1 at dodo.com.au> Mar 20, 2006
- 575 views
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!
10. Re: delete bytes?
- Posted by Salix <salix at freemail.hu> Mar 20, 2006
- 555 views
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
11. Re: delete bytes?
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 20, 2006
- 567 views
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
12. Re: delete bytes?
- Posted by Brian Broker <brian_broker at yahoo.com> Mar 20, 2006
- 569 views
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