Re: Reading/Writing text files
Re: Reading/Writing text files
- Subject: Re: Reading/Writing text files
- From: John Delacour <email@hidden>
- Date: Sat, 17 Aug 2002 08:07:54 +0100
At 9:39 am -0700 16/8/02, Sara Lewin wrote:
I am trying to open a text file - that may or may not
exist and than erase everything in the file and write
text to it.
I suppose I could delete the file and than create it?
But I am unsure what the code for this would look
like.
'open for access' will create the file if it doesn't exist, so all
you need is a pathname (_string_). Don't try 'alias "pathname"'
because you'll get an error if the file doesn't exist.
---
set f to "dsk:fol:f"
try
close access file pathname
on error someerror
end try
open for access file f with write permission--[creates and] opens
set eof file pathname to 0 -- erases contents
write "new text" to file f -- writes data
close access file f
---
You can use the file id method if you like, but I never do.
The try block at the beginning is just to save you inconvenience
while building the script in case an error leaves the file busy.
JD
PS. Are all G4's unacceptably noisy? My 867 is the noisiest machine
I've ever owned and although Apple have just replaced the whining
hard disk and I'm getting the machine back today, I fear that the fan
etc. will still be just as noisy. I know several powerful PCs of no
particular distinction that are virtually silent.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.