Changes

Jump to: navigation, search

Constructing and Manipulating Paths with NSPathUtilities

955 bytes added, 21:09, 11 November 2009
no edit summary
== Getting the Current User's Home Directory ==
 
The home directory of the current user can be identified using the ''NSHomeDirectory()'' function. This function takes no arguments and returns an NSString object containing the path to the home directory of the user executing the program:
 
<pre>
NSString *homedir;
 
homedir = NSHomeDirectory();
 
NSLog (@"Home directory of current user is %@", homedir);
 
</pre>
 
== Getting the Home Directory of a Specified User ==
 
The home directory of any user on a system can be obtained using the ''NSHomeDirectoryForUser()'' function. This function takes as its sole argument an NSString object containing the name of the user and returns another NSString object containing the corresponding home directory:
 
<pre>
NSString *homedir;
NSString *username = @"Paul";
 
homedir = NSHomeDirectoryForUser(username);
 
NSLog (@"Home directory of user %@ is %@", username, homedir);
</pre>
 
If the requested user does not exist on the system the function will return null.
== Extracting the Filename from a Path ==

Navigation menu