Re: Problems Writing to a File
Re: Problems Writing to a File
- Subject: Re: Problems Writing to a File
- From: has <email@hidden>
- Date: Thu, 10 Nov 2005 19:14:42 +0000
Steve Suranie wrote:
>I'm trying to write to a file but I am having some problems with my script:
>
>set theFilePath to (path to desktop) & "archiveTool:htmlFiles:tempFile.txt" as string
Concatenating an alias and a string and coercing the resulting two-item list to a string is not a particularly safe move; think TIDs. Another problem is that HFS paths cannot distinguish between identically named drives, so if you have another drive mounted with the same name then it's a crapshoot as to which one your path will refer to. A third source of potential errors is using 'as string' instead of 'as unicode text' coercions on unicode-based data: throw in some fancy 'foreign' characters and it can easily break, although that won't be the cause in your particular case since all your filesystem names are ASCII-compatible.
Anyway, here's how I'd do it, eliminating TID issues and using posix paths to avoid any drive name collisions (the redundant 'tell app "Finder"' block and 'my' keyword have also been cleaned out):
set theFileRef to POSIX file (POSIX path of (path to desktop) & "/archiveTool/htmlFiles/tempFile.txt")
set theContent to "This is a test"
writeFile(theFileRef, theContent)
--subs--
on writeFile(theFileRef, theContent)
set f to (open for access theFileRef with write permission)
write theContent to f
close access f
end writeFile
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden