How to use Open File For Appending

I'm trying to use the command, Open File For Appending. The following example creates the file, but only with the contents "test3". The appending is not working. Is the syntax in my example code incorrect ?

if there is no file TestResults1 then create file TestResults1
open file "TestResults1" for appending

put "test1" into file "TestResults1"
put "test2" into file "TestResults1"
put "test3" into file "TestResults1"

write file & return to file "TestResults1"
close file "TestResults1"

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    The syntax you are using is meant to be used with the "write ? to" syntax, not the "put ? into" syntax. The "put ? into" syntax is always going to overwrite whatever the file contents are; you can append by using the "put ? after" syntax:
    put "test1" & return after file "TestResults1"
    put "test2" & return after file "TestResults1"
    put "test3" & return after file "TestResults1"
    
    Note that your other code becomes unnecessary; EggPlant will automatically create the file if it doesn't exist and do all of the opening and closing.
  • Nice! Thanks for the guidance. Works great!
Sign In or Register to comment.