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

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

问题描述

BBEdit的一个不错的功能是如何跟踪文件,无论这些文件发生什么。我正在处理的应用程序需要跟踪用户拥有的许多文件的位置。用户可以移动或删除这些文件,我的应用程序需要知道这些文件是哪里,即使我的应用程序没有在发生位置发生变化时运行。



我的问题是什么建议的战略,这个问题是或可以是?在应用程序运行时跟踪文件不是问题。当我的应用程序没有运行时,我的应用程序运行时,我想要正确的文件路径。



手动搜索文件

解决方案

从10.6开始,它是通过书签功能 NSURL


书签是一种新的工具,由URL标识的资源。书签是系统从资源URL生成的数据对象。书签数据封装对底层资源的持久的,不透明的引用以及在创建书签时捕获的资源属性的值。书签可以存储在内存或磁盘上,以后用于访问其包含的资源属性值,或者解析为覆盖底层资源的URL。在文件系统资源的情况下,书签能够定位自创建书签以来已移动或重命名的资源,类似于别名管理器别名。请注意,在此版本中,书签仅按路径解析。



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


$ b (NSURL *)相对URL错误:(NSURL **)错误;(NSURL *)相对URL错误:(NSURL *)错误。
- (NSURL *)initByResolvingBookmarkData:(NSData *)bookmarkData选项:(NSURLBookmarkResolutionOptions)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:
+(NSURL *)URLByResolvingBookmarkData:(NSData *)bookmark数据选项:(NSURLBookmarkResolutionOptions)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:
+(NSDictionary *)resourceValuesForKeys:(NSArray *)keys fromBookmarkData:(NSData *)bookmarkData;


在10.6之前,使用 别名


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.

My question is what a recommended strategy for this problem is or could 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.

Is manually searching for the files the best approach or is there an API that I am overlooking that makes this easier?

解决方案

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

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.

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;

Before 10.6, it was done with aliases.

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

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