gpt4 book ai didi

cocoa - 如何跟踪 Mac OS X 上的文件位置?

转载 作者:行者123 更新时间:2023-12-03 16:07:26 29 4
gpt4 key购买 nike

BBEdit 的一个很好的功能这就是它跟踪文件的方式,无论这些文件发生什么情况。我正在开发的应用程序需要跟踪用户拥有的许多文件的位置。用户可以移动或删除这些文件,即使位置发生更改时我的应用程序没有运行,我的应用程序也需要知道这些文件的位置。

解决这个问题的推荐策略是什么或者可能是什么?

在应用程序运行时跟踪文件不是问题。当我的应用程序运行时,我想要文件的正确路径,无论当我的应用程序未运行时这些文件发生了什么。

手动搜索文件是最好的方法还是有一个我忽略的 API 可以让这变得更容易?

最佳答案

从10.6开始,通过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;

10.6之前,是用aliases完成的.

关于cocoa - 如何跟踪 Mac OS X 上的文件位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10276026/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com