Retrieving location of Documents and Shared dirs

Archives Forums/MacOS X Discussion/Retrieving location of Documents and Shared dirs

JazzieB(Posted 2007) [#1]
On Windows, it has becomes necessary to retrieve the location of My Documents and the Common Apps Data Folder via special calls to the OS (due to language differences and the need to store data in the proper folders). So, my question is simple ... Can the following two folders be retrieved from the OS, so that I don't need to make the assumptions I have below?

1) /Users/<user>/Documents

The user folder can be retrieved from environment variables, which isn't a problem. However, what you don't get is the "Documents" on the end of it. I don't want to just add it manually, as it most likely will not be called this on a version of OS X that is for a non-English speaking country.

2) /Users/Shared

Similar to above really. Can the location of the Shared User folder be retrieved from somewhere, as I believe there isn't an environment variable that returns it. Don't want to assume it's just called "Shared", for the same reason as above. Also, is this folder always present?


If anyone can help, and give an example if possible, that would be great.


SebHoll(Posted 2007) [#2]
Regarding one of your queries, you can use Brucey's fantastic cross-platform module called BaH.Volumes that will get you the location of Documents, Program Files, App Data and also tell you how much space drives have left, and how big they are, all through simple commands.

You can download it here or via syncmods using the following command line:

syncmods -u forumusername -p forumpass bah.volumes


JazzieB(Posted 2007) [#3]
Yep, should sort me out as for as the Documents folder goes. Cheers.

Just need to know if there's any way of getting the Shared folder, as this is my preferred location for non-user specific game data.


Brucey(Posted 2007) [#4]
According to Folders.h (part of the API docs), it's at :

kSharedUserDataFolderType = 'sdat', /* A Shared "Documents" folder, readable & writeable by all users */

You want me to add it to the Mac Volumes type?
Also, if you can think of any other folder types that might be useful, I could sort them out too.

:-)


JazzieB(Posted 2007) [#5]
If you could add that, that would be great. Can't really think of anything more that I would need, but others may decide to add one or two others.

Also, I've noticed that the ZIP file contains .i and .a files for PPC, but none for the Intel Macs. Do I need to worry about this, or will it still work? Sorry, not had a chance to test it yet on my Intel Mac. EDIT -- Just checked and it works fine :)

Cheers for your help.


Brucey(Posted 2007) [#6]
Am adding a GetCustomDir function, in which you pass a "dir type", which will allow for a bit of flexibility on my end, rather than adding special functions that only work on one platform.
eg.
source :
SuperStrict

Framework BaH.Volumes
Import BRL.Standardio

Print GetCustomDir(DT_SHAREDUSERDATA)

output:
Executing:untitled1.debug
/Users/Shared

Process complete


No Intel Mac here, I'm afraid, but fortunately a Build Modules doesn't take too long to run...


JazzieB(Posted 2007) [#7]
Nice work, and can't fault the quick service. Very much appreciated.

Just realised all I needed to do was build the modules. Doh!

Let me know when your changes are available. And thanks again.


Brucey(Posted 2007) [#8]
New version is up on the site...

Can only do PPC syncmods I'm afraid (which is up also), as one requires the specific platform/combo to upload to that.

Please let me know if you have any problems with it.

Thanks :-)


Tachyon(Posted 2007) [#9]
No, thank YOU Brucey!!!


Brucey(Posted 2007) [#10]
Glad I can be of help ;-)

Anyways... back to the Flight Dynamics module...


JazzieB(Posted 2007) [#11]
Works a treat. Thank you.