|
#1
| |||
| |||
| 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 |
|
#2
| ||||
| ||||
|
__________________ 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 |
|
#3
| |||
| |||
| 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 |
![]() |
| Thread Tools | |
|
|