image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
Thread Tools
  #1  
Old June 16th, 2008, 06:52 PM
Registered User
 
Join Date: Sep 2002
Location: Parker, Colorado
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
kuroyume is on a distinguished road
Get current user path?

On a multi-user machine, how would one get the current user's folder path (i.e.: /Users/<user>) in Carbon only (Xcode C++). Seems that using environmental variables (getenv()) returns nothing for "PWD".

Thanks,
Robert
__________________
Kuroyume's DevelopmentZone
Reply With Quote
  #2  
Old June 17th, 2008, 09:25 AM
ElDiabloConCaca's Avatar
U.S.D.A. Prime
 
Join Date: Aug 2001
Location: San Antonio, Texas
Posts: 10,377
Thanks: 3
Thanked 124 Times in 113 Posts
ElDiabloConCaca is a jewel in the roughElDiabloConCaca is a jewel in the roughElDiabloConCaca is a jewel in the rough
Does this help?

http://lists.apple.com/archives/carb.../msg00840.html
__________________
Power Macintosh G4/500MHz "Yikes!" 10.4.11 Server • 1024MB • 3 x 120GB + 320GB • DVR-111D • 2 x Radeon 7000 PCI • 2 x 17" CRT
MacBook 2.0GHz Core 2 Duo - White 10.5.5 • 2048MB • 80GB • CD-RW/DVD-ROM
iPod Photo 60GB • iPod nano 1GB • AT&T DSL 6Mb/768k
http://www.jeffhoppe.com
Reply With Quote
  #3  
Old June 17th, 2008, 01:41 PM
Registered User
 
Join Date: Sep 2002
Location: Parker, Colorado
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
kuroyume is on a distinguished road
I eventually found something but it took about twenty variations on wording (in the end, since the current user's Library:Preferences was my target, that helped).

So, here's my little code - works great:

Code:
#include "Folders.h"

// METHODS: MacUserPrefs
// Get Users Preferences folder
//*---------------------------------------------------------------------------*
String MacUserPrefs::GetUserPrefs()
//*---------------------------------------------------------------------------*
{
	// ask MacOS to find the users preferences folder (/Users/{username}/Library/Preferences/ on US-english MacOS X)
	// see http://developer.apple.com/samplecode/MoreFilesX/listing2.html
	// and http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html#//apple_ref/c/func/FSFindFolder
	// and http://developer.apple.com/samplecode/FileNotification/listing1.html
	FSRef	fsRef;
	char	path[1024];
	OSErr	tError =	noErr;

	tError =			FSFindFolder(kOnAppropriateDisk, kPreferencesFolderType, kDontCreateFolder, &fsRef);
	tError =			FSRefMakePath(&fsRef, (UInt8*)path, 1024);
	return	String(path);
}
__________________
Kuroyume's DevelopmentZone
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 11:27 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.