MACSCRPT Archives

May 2008

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
deivy petrescu <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 13 May 2008 12:03:40 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (42 lines)
On May 13, 2008, at 10:55, Bill Steele wrote:

> I'm writing RSS files. When the file needs to be updated, I've been  
> deleting the old version and writing new text to a new file. Seems  
> like a lot of extra work. But if I write the new text to the old  
> file "starting at 0" what happens if the old text is longer than the  
> new?
>
> I can write spaces to the file from 0 to eof, but then I might end  
> up with a bunch of wasted space at the end.
>
> Doing ACME Replace on the entire text also seems a bit extreme.
>
> Is there a simple way to wipe the contents of the file without  
> deleting and recreating?
>
> I'm prepared to feel stupid if it turns out to be really obvious.
> -- 
>
> Bill Steele
> [log in to unmask]

Bill,
This is what you want:

<script>
set l to "my new text"
set ofile to theFileIwantToWriteTo as string -- you do not have to  
have it as string, but then erase "file" from the two lines below.
set eof of file ofile to 0
write l to file ofile
<script>

You do not need to open for write. Just copy the script above.
It will prevent errors by you forgetting to close access to the open  
file.

Setting the eof to 0 erases the file contents.


Deivy

ATOM RSS1 RSS2