how do i append a text to an existing txt file?

Just starting out? Need help? Post your questions and find answers here.
debaser
New User
New User
Posts: 7
Joined: Tue May 10, 2005 1:59 pm

how do i append a text to an existing txt file?

Post by debaser »

well

my application is a notepad that should add to a text file (*.txt) the new comments i write.
i just have a text editor and a "save" button. when i push save it has to add the new text to a specified txt file.

Code: Select all


      OpenFile(0, "appunti.txt")
      WriteString(String$)
      CloseFile(0)
with this code it overwrites everytime the first line....
[/code]
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

Code: Select all

  OpenFile(0, "appunti.txt") 
Fileseek(lof())    
  WriteString(String$) 
      CloseFile(0) 
Correct it! thanks D*
Last edited by sec on Tue Jun 07, 2005 2:52 pm, edited 1 time in total.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Code: Select all

If OpenFile(#_file, "outdoc.txt")
  FileSeek(lof())
  WriteStringN("<< APPENDED >>")
  CloseFile(#_file)
EndIf
Whup - slow typer. As Sec showed.
Last edited by Dare2 on Tue Jun 07, 2005 2:41 pm, edited 1 time in total.
@}--`--,-- A rose by any other name ..
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Post by Doobrey »

Shouldn't it be FileSeek(Lof()) instead of FileSeek(Eof())?

Edit.. beaten to it by Dare2 :roll:
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

Doobrey wrote:Shouldn't it be FileSeek(Lof()) instead of FileSeek(Eof())?

Edit.. beaten to it by Dare2 :roll:
my typo .
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

It's a three-way tie!

:)
@}--`--,-- A rose by any other name ..
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Post by Doobrey »

Dare2 wrote:It's a three-way tie!

:)
OK, deathmatch it is then ... :twisted:
Or would you prefer rock,paper,scissors ?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

rofl. :D

paper!
@}--`--,-- A rose by any other name ..
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: how do i append a text to an existing txt file?

Post by PB »

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply