出于某种原因,我无法对 bundle 内的文件和驻留在不同卷上的文件执行此操作。
我是唯一遇到此问题的人吗?如果没有我该如何解决?
对于我遇到问题的相同文件,Finder 似乎在显示聚光灯属性方面没有困难。
我想获取文件的 kMDItemKind 以及其他一些属性。
CFStringRef path = CFSTR("/Applications/Chess.app/Contents/Info.plist"); // bad
// CFStringRef path = CFSTR("/Applications/Chess.app"); // good
MDItemRef item = MDItemCreate(kCFAllocatorDefault, (CFStringRef)path);
if(!item) {
NSLog(@"MDItemCreate returned NULL for path: %@", path);
return nil;
}
CFStringRef kind = MDItemCopyAttribute( item, kMDItemKind );
if(kind) {
NSLog(@"file: %@ kind: %@", path, (NSString*)kind);
CFRelease( kind );
} else {
NSLog(@"file: %@ has no kMDItemKind attribute", path);
}
CFRelease( item );
输出:
file: /Applications/Chess.app/Contents/Info.plist has no kMDItemKind attribute
如果我使用命令行工具 mdls,也会出现同样的问题,如下所示
prompt> mdls /Applications/Chess.app/Contents/Info.plist
kMDItemFSContentChangeDate = 2009-05-19 08:09:03 +0200
kMDItemFSCreationDate = 2009-05-19 08:09:03 +0200
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = 0
kMDItemFSLabel = 0
kMDItemFSName = "Info.plist"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 0
kMDItemFSOwnerUserID = 0
kMDItemFSSize = 3294
kMDItemFSTypeCode = ""
如您所见,返回的数据非常少,并且没有 kMDItemKind
如何获取 Info.plist 的元数据?
最佳答案
Obtain
kMDItemKind
on files inside bundles returns nil
正确。您无法获取元数据尚未索引的文件的元数据属性,并且它不会对 bundle 内、某些文件夹中以及任何禁用索引的卷(包括但不限于只读卷)上的文件进行索引,其中元数据无法将索引写入卷)。
The Finder seems not having difficulties showing spotlight properties for the same files that I'm experiencing problems with.
你如何测试这个?我获得了有关 PNG 文件以及应用程序包内的 PNG 文件的信息;第一个具有常见的图像属性(例如尺寸),但 bundle 内的图像没有显示任何内容。
如果您只想要 Kind,请使用 the LSCopyKindStringForURL
function 。与大多数核心服务功能一样,它遵循 the CF memory-management rules .
关于macos - 获取包内文件的 kMDItemKind 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3517320/