Re: Plist
Re: Plist
- Subject: Re: Plist
- From: James Bucanek <email@hidden>
- Date: Thu, 29 Dec 2011 09:26:36 -0700
Motti Saroka <mailto:email@hidden> wrote (Thursday,
December 29, 2011 3:56 PM +0200):
Hi,
I have a problem, I need to load a Plist file that contain a "WatchPaths"
tag which should point to user home directory, this Plist file should be
generic and should match to different users, the problem is that I don't
know the username before I am loading the Plist by launchctl, ideally is to
use the tag "$HOME" or "~" whoch point to the user home directory from
command line but MacOSX don't recognize these tags, what alternative way I
should use in order to use the "WatchPaths" and point to a local user home
directory.
This really isn't a filesystem question. You'd be better off
posting this to the Cocoa-dev list, if this doesn't answer your question.
The function you're probably looking for is -[NSString stringByExpandingTildeInPath].
Very few file manager function in Cocoa recognize the ~ in a
path as a shortcut to the current user's home directory. You can
resolve this simply by first sending the string the
-stringByExpandingTildeInPath message. The returned string will
be an absolute file system path with ~ replaced with the
appropriate home directory path, which you can then pass to any
file system method.
Here's an example
NSString* path = @"~/myfile.plist";
NSFileManager* fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:[path stringByExpandingTildeInPath]])
...
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Plist (From: Motti Saroka <email@hidden>) |