Re: Files can't be saved to the relative paths?
Re: Files can't be saved to the relative paths?
- Subject: Re: Files can't be saved to the relative paths?
- From: Uli Kusterer <email@hidden>
- Date: Sun, 19 Aug 2007 05:42:47 +0200
On 19.08.2007, at 12:51, Steve wrote:
code like these: folderPath = @"$HOME/Desktop", the tiffDate
writeToFile function never works. I don't know why, perhaps you
have to write to absolute path?
$HOME is a shell variable. Luckily MacOS doesn't interpret commands
and shell variables in its paths (unless you're typing your paths
into a shell obviously) -- would be much too easy to make exploits if
it did. writeToFile: and most other Cocoa APIs on the Mac take a
POSIX path, which is usually absolute. It also supports relative
paths, but they're relative to the current working directory, which
may change at any time, so you really don't want to rely on the
current working directory in any way.
There is an NSString method (in NSPathUtilities.h) that lets you
expand a tilde in a path and turn this into a full, absolute path
based in the home directory, and there's also other useful functions
in there, like NSHomeDirectory(), NSHomeDirectoryForUser() and
NSSearchPathForDirectoriesInDomains(). The latter with the constant
NSDesktopDirectory would probably be your best bet, as the desktop
folder has moved twice before, and may do so again, and hard-coding ~/
Desktop may be dangerous.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden