Part of the Samples Website. 8/16/97.

samples.basicStuff.writeTextFile

«Creates a text file containing the names of the 50 states
«the file is created on the system disk, at the top level, its name is "textfile"
«if the file exists, we confirm with the user that it should be replaced
«we create a new file of type 'TEXT' and creator 'ttxt'
«then we write the names of the 50 states to the file
«when the loop is done, we report the number of characters in the file
«should be 472
«and offer to open the file
local (path = file.getSystemDisk () + "textfile")
if file.exists (path) «confirm that the user wants to over-write it
if not dialog.confirm ("Replace existing file?")
return
file.delete (path)
file.new (path) «create the file
file.setType (path, 'TEXT') «it's a text file
file.setCreator (path, 'ttxt') «it can be opened by TeachText
file.open (path)
for i = 1 to 50
file.writeLine (path, states.nthState (i))
file.close (path)
if dialog.yesNo (file.size (path) + " characters in the file. Open it?")
launch.anything (path)


This page was last built on Sat, Aug 16, 1997 at 6:42:28 PM. You can download the current set of sample scripts from our FTP site. Dave