How to track file locations on Mac OS X?

One of the nice features of BBEdit is how it tracks files no matter what happens to those files. The application I'm working on should track the location of a number of files owned by the user. The user can move or delete these files, and my application should know where these files are, even if my application did not work during the change of location.

What is the recommended strategy for this problem or what could it be?

Tracking files while the application is running is not a problem. I want to indicate the correct file path when my application is running, regardless of what happened to these files when my application was not running.

Manual file search is the best approach, or am I missing an API that makes this task easier?

+7
source share
1 answer

Starting with 10.6, this is done using the NSURL Bookmarks NSURL :

Bookmarks are a new tool for creating permalinks to resources identified by URLs. A bookmark is a data object generated by the system from the resource URL. Bookmark data encapsulates a solid, opaque link to the underlying resource, as well as the value of the resource properties captured when the bookmark was created. A bookmark can be saved in memory or on disk, and then used to access the property values ​​of the resource that it contains, or allowed to cover the URLs of the main resources. In the case of file system resources, a bookmark can find resources that have been moved or renamed since the bookmark was created, similar to Alias ​​Manager aliases. Please note that in this version bookmarks are only allowed along the way.

The following new NSURL methods are further described in NSURL.h:

 - (NSData *)bookmarkDataWithOptions:(NSURLBookmarkCreationOptions)options includingResourceValuesForKeys:(NSArray *)keys relativeToURL:( NSURL*)relativeURL error:(NSURL **)error; - (NSURL*)initByResolvingBookmarkData:(NSData*)bookmarkData options:(NSURLBookmarkResolutionOptions)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:(NSError **)error; + (NSURL *)URLByResolvingBookmarkData:(NSData *)bookmarkData options:(NSURLBookmarkResolutionOptions)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:(NSError **)error; + (NSDictionary *)resourceValuesForKeys:(NSArray *)keys fromBookmarkData:(NSData *)bookmarkData; 

Prior to 10.6, this was done using aliases .

+12
source

All Articles