writing to prefs file in a folder in the prefs folder

I’m writing a bot for ircle and I’ve got it writng it’s prefs and user data to five different files in the prefs folder and that works but I want it to create a folder in the prefs folder and write it’s prefs files in there. I don’t like having all 5 files scattered around in the prefs folder. I figure there’s got to be a way to make it make a new folder in the prefs folder and keep all if it’s data files together. Originally I had this:

set prefPath to path to preferences as string
set prefPath to prefPath & “SkyBot Config Prefs”
set prefFile to open for access file prefPath with write permission
write configData & return to prefFile
close access prefFile

I do this 5 different times for 5 different files and that works but then I tried something like this:

set prefPath to path to preferences as string
set prefPath to prefPath & folder “SkyBot Prefs”
set prefPath to prefPath & “SkyBot Config Prefs”
set prefFile to open for access file prefPath with write permission
write configData & return to prefFile
close access prefFile

But that doesn’t even compile. I tired putting new line in a tell to the finder which gets it to compile but throws an error “Can’t make prefrences in to an item”. I’ve tried several different ways but I can’t seem to get it to write to a file in a folder in the Prefrences folder. Any ides?

You can try this one:

savePrefs("Foo", "SkyBot Config Prefs")

to savePrefs(prefs, prefName)
	set SkyBotPrefsFolder to ((path to preferences as text) & "SkyBot Prefs:")
	try --> test if folder exists
		alias SkyBotPrefsFolder
	on error --> create such folder
		do shell script "mkdir -p " & quoted form of POSIX path of SkyBotPrefsFolder
	end try
	
	--> ... And write to the specified file
	set fRef to (open for access file (SkyBotPrefsFolder & prefName) with write permission)
	set eof of fRef to 0
	write prefs to fRef
	close access fRef
end savePrefs

Yup, That did the trick. Thanks a bunch. :smiley: