[Solved] Writing data to text file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
redfield
Posts: 95
Joined: Thu Apr 04, 2019 1:41 pm

[Solved] Writing data to text file

Post by redfield » Mon May 20, 2019 8:03 pm

Hi guys,
I found two different ways of writing data into text files. Both methods work for me, so I am wondering what may be the difference between them? Any advantages or disadvantages?

1.

Code: Select all

put specialfolderpath("Home") & "/test" into theFile
open file theFile for write 
write "hello" to file theFile
close file theFile

2.

Code: Select all

put "file:" & specialfolderpath("Home") & "/test" into theFile
put "hello" into line 1 of URL(theFile)
Last edited by redfield on Sun Jun 16, 2019 12:49 pm, edited 1 time in total.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Writing data to text file

Post by Klaus » Mon May 20, 2019 8:13 pm

The url syntax is shorter! :D

1. The "open file..." syntax is better suited when dealing with LARGE files like server log file with hundreds of MB.

2. The url syntax will read the complete content of the file into RAM do what you want it to and then write it back to disk. Since nowadays we ususally have LOTS of ram installed on our machines, most of the time this will work fine.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Writing data to text file

Post by FourthWorld » Mon May 20, 2019 8:14 pm

To write a file in one pass, the URL is method is simpler to write. If you need to do multiple writes, seeks, or other operations beyond a one-pass write, the "open file" and "close file" commands are what you'd use for that flexibility.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Writing data to text file

Post by Klaus » Mon May 20, 2019 9:44 pm

FourthWorld wrote:
Mon May 20, 2019 8:14 pm
To write a file in one pass, the URL is method is simpler to write. If you need to do multiple writes, seeks, or other operations beyond a one-pass write, the "open file" and "close file" commands are what you'd use for that flexibility.
Yes, and that. :-)

Post Reply