writing to files

ok this is probably a really dumb question but my application is dumping a file into a text view then after the user edits it dumps it back out to the file…
the file is an admin file for a cvs repository so therefore is unix based…
my problems arise when i attempt to open the file for writing i get a duplicate file name error…

set l_file to open for access l_fName with write permission

and then when i remove the file and start from scratch when i write to my new file i seem to get a unicode output which i have no idea how to convert to the desired format…

write l_contents to l_file

does anybody have any solutions??
thanks

It’s rough trying to determine what might be going wrong without seeing more of the code. Does the script ever close the file?

i close the file directly after writing…
here is the entire function

– g_cvsignore is a posix style path
on saveFile(theObject)

set l_toSave to contents of text view “txt_text” of scroll view “txt_text” of window of theObject

set g_cvsignore to (POSIX file g_cvsignore)

set l_file to open for access (g_cvsignore as text) with write permission

set eof of l_file to 0

write (l_toSave as string) to l_file

close access l_file

set visible of window of theObject to false
end saveFile

As near as I can tell, you are trying to open a string for access (g_cvsignore as text). What happens if you change this line:

set l_file to open for access (g_cvsignore as text) with write permission

To this?

set l_file to open for access file (g_cvsignore as text) with write permission

yeah, i feel a bit stupid after that…
it’s working perfectly now…
rob, you da man…

Nah, not stupid at all. It’s easy to overlook little things like that when you stare at the code for too long and frustration sets in. :shock:

Glad it helped to have some fresh eyes. :smiley: