[comp.sys.mac.programmer] Need sample code for folder/file lookup.

wdh@well.sf.ca.us (Bill Hofmann) (06/27/90)

In article <460@tci.UUCP> mitchell@tci.UUCP (Rob Mitchell) writes:
>Hey fellow Mac'ers,
>
>	Could someone share a quick and easy way of finding out if
>the System folder (blessed) exists on a volume or not?  And also if
>a preference-like file exists inside the System file?

If it's the system folder of the current boot volume, why not use
SysEnvirons?  One of the fields is sysVRefNum.  I'm not sure why you'd
want to put a prefs file in a system folder on a non-boot drive, so
I think this'll solve it for you.  Then, try to create your pref file,
if it exists (that is, you get an "already exists" error), open it, 
otherwise, open and init it.

-Bill Hofmann

rdsesq@jessica.stanford.edu (Rob Snevely) (06/28/90)

Getting the sysVRefNum from SysEnvirons is a very easy way to get
the blessed folder. Then try to open the file, if you get an error
that no such file exists then create the file.

rob snevely

rdsesq@jessica.stanford.edu

h+@nada.kth.se (06/30/90)

Sorry if this is goofed, I have no news except raw NNTP
in telnet...

Be sure to create your prefs file in the folder "Preferences"
in the system folder. Someone said that you just had to add
"Preferences:" before the name to have to folder created
automagically if it didn't exist.

If you want to be really nice, you could have a STR resource
named "Preferences folder name" containing the string
"Preferences:", and prepend the contents of this string, so
that international users can have what they want...

Thsi is h+@nada.kth.se, directly for NNTP news

t-alexc@microsoft.UUCP (Alex CHAFFEE) (07/03/90)

In article <1990Jun30.155142.885@kth.se> h+@nada.kth.se writes:
>Be sure to create your prefs file in the folder "Preferences"
>in the system folder. Someone said that you just had to add
>"Preferences:" before the name to have to folder created
>automagically if it didn't exist.

Uh, that was me, and I was wrong.  I hit "cancel" within the hour,
but apparently the misinformation got out...  To atone, I posted a
function I wrote called CreatePath which does what I said PBHCreate
does (but doesn't).  If you like, I can repost.

>If you want to be really nice, you could have a STR resource
>named "Preferences folder name" containing the string
>"Preferences:", and prepend the contents of this string, so
>that international users can have what they want...

Actually, a STR with ":Preferences:My Prefs" works fine as input to
CreatePath.  And if the Preferences folder already exists, it works
fine with other programs too.  So if you want to reduce your system
folder clutter, find others' preference file name resources and add
":Preferences:" to the beginning.

- Alex Chaffee
  microsoft!t-alexc