[quote=“SenseTalkDoug”]The simple way to append to a file is just to treat it as a container and use the “put … after” command:
put newResult & return after file "/tmp/testresult.txt"
Using the open file command, here is the code that will do the same thing:
open file "/tmp/testresult.txt" for appending
write newResult & return to file "/tmp/testresult.txt"
close file "/tmp/testresult.txt"
Using this approach, you could open the file at the beginning of your script, then use write commands at various points to write additional results to the file, and finally close the file at the end of your script run. This may be slightly more efficient since the “put … after” command will open and close the file each time, but unless your result file is very large I don’t think the difference will be noticeable.[/quote]
Thank you very much, I like the second approach better, it’s more efficient.
I have another question, how can I create a file using a variable as it’s name, the code:
put “filename” into fname
put “.txt” after fname
create file “/tmp/[[fname]]” --It doesn’t work and encounter an error
how can I create a file using the variable fname as it’s name, thanks.