• 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: How do I get a file reference w/o relying on the path?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I get a file reference w/o relying on the path?


  • Subject: Re: How do I get a file reference w/o relying on the path?
  • From: Brad Stone <email@hidden>
  • Date: Sun, 18 Apr 2010 10:43:14 -0400

I'm storing the bookmark data in an array displayed in a table:
NSData *bookmarkData = [inAbsoluteURL bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile
								includingResourceValuesForKeys:nil
								relativeToURL:nil
								error:&error];




When the user double clicks on the row in the table I want to open the file.  I use this:
NSError *error;
BOOL isStale;
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmarkData options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];

When the file's name or directory changes on my hard drive the resolved url == nil.   I'd like it to resolve to the actual file even if my app is closed and opened again (I'm saving the bookmarkData to repopulate the table the next time the user opens my app).  I thought that's what bookmarks did in 10.6 - I could be wrong.  An ugly workaround would be when the user double-clicks for me to create an actual alias file in a temp folder from the bookmark data and store that in my array, recreate it in a temp folder and launch that.  I'm sure that's wrong - there has got to be a better way.


On Apr 3, 2010, at 6:55 PM, Ken Thomases wrote:

> On Apr 3, 2010, at 5:20 PM, Brad Stone wrote:
>
>> I want to store a reference to a file in an ivar that will allow the user to change the file's name and/or the directory (i.e. the path) and still allow me to access it.  I don't want to create a file (like an ailas).  I need to store the file reference in a variable so I can open the file no matter where the user moves it or renames it.
>
> FSRefs have the property you desire.  As of Snow Leopard, though, the new recommended technique is to use a file reference NSURL.  Check the NSURL documentation and also:
>
> http://developer.apple.com/mac/library/documentation/cocoa/conceptual/LowLevelFileMgmt/Articles/FileManagementNSURL.html
>
>
> Note that an alias _record_ is different from an alias _file_.  An alias record is data in memory and is suitable for this purpose, but perhaps overkill.
>
> As of Snow Leopard, alias records are deprecated in favor of bookmark data, but, again, it's probably overkill.  (Both alias records and bookmark data are more suitable if the reference is to be persisted for use by a later process.  Also, both can apply more robust searching heuristics to find an appropriate file even if it isn't the original.  For example, if the original is deleted and replaced with a new file of the same name.)
>
> Cheers,
> Ken
>

_______________________________________________

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

  • Follow-Ups:
    • Re: How do I get a file reference w/o relying on the path?
      • From: Charles Srstka <email@hidden>
    • Re: How do I get a file reference w/o relying on the path?
      • From: Noah Desch <email@hidden>
References: 
 >How do I get a file reference w/o relying on the path? (From: Brad Stone <email@hidden>)
 >Re: How do I get a file reference w/o relying on the path? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Text file
  • Next by Date: +Hi+
  • Previous by thread: Re: How do I get a file reference w/o relying on the path?
  • Next by thread: Re: How do I get a file reference w/o relying on the path?
  • Index(es):
    • Date
    • Thread