• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Files can't be saved to the relative paths?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Files can't be saved to the relative paths? (From: Steve <email@hidden>)

  • Prev by Date: Subclass of NSTextView resizes strangely...
  • Next by Date: Re: Files can't be saved to the relative paths?
  • Previous by thread: Re: Files can't be saved to the relative paths?
  • Next by thread: Re: Files can't be saved to the relative paths?
  • Index(es):
    • Date
    • Thread