如何在Mac OS X上跟踪文件位置? [英] How do I keep track of file locations on Mac OS X?

查看:269
本文介绍了如何在Mac OS X上跟踪文件位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BBEdit 的一项不错的功能是无论如何跟踪文件发生在那些文件上。我正在处理的应用程序需要跟踪用户拥有的多个文件的位置。用户可以移动或删除这些文件,并且即使发生位置更改时我的应用程序未运行,我的应用程序也需要知道这些文件在哪里。

One of the nice features of BBEdit is how it keeps track of files no matter what happens to those files. The application that I am working on needs to keep track of the location of a number of files owned by the user. The user can move or delete these files and my application needs to know where those files are even if my application was not running at the time the change in location happened.

什么是针对此问题的推荐策略,或者可能是什么?

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

在应用程序运行时跟踪文件不是问题。无论应用程序未运行时那些文件发生了什么情况,我都希望它们在运行时具有正确的文件路径。

Keeping track of files while the application is running is not the problem. I want the correct path to the files when my application is running no matter what happened to those files when my application was not running.

手动搜索最佳文件

推荐答案

从10.6开始,它是由书签完成的 NSURL 的功能:

Starting from 10.6, it is done by "Bookmarks" functionality of NSURL:


书签是一种新功能,用于生成对URL标识的资源的持久引用。 。书签是系统从资源URL生成的数据对象。书签数据封装了对基础资源的持久,不透明的引用,以及在创建书签时捕获的资源属性的值。书签可以存储在内存或磁盘中,以后可以用来访问其包含的资源属性值,也可以解析为覆盖基础资源的URL。对于文件系统资源,书签能够查找自创建书签以来已移动或重命名的资源,类似于Alias Manager别名。请注意,在此版本中,书签仅按路径解析。

Bookmarks are a new facility for generating persistent references to resources identified by URLs. A bookmark is a data object generated by the system from a resource URL. The bookmark data encapsulates a durable, opaque reference to the underlying resource as well as value of resource properties captured when the bookmark was created. A bookmark can be stored in memory or on disk and later used to access the resource property values it contains, or resolved to cover the underlying resource’s URL. In the case of file system resources, the bookmark is capable of locating resources that have been moved or renamed since the bookmark was created, similar to Alias Manager aliases. Note that in this release, bookmarks resolve only by path.

NSURL.h中进一步记录了以下新的NSURL方法:

The following new NSURL methods are further documented 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;


在10.6之前,它是通过 别名

Before 10.6, it was done with aliases.

这篇关于如何在Mac OS X上跟踪文件位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆