通过NSFileManager获取元数据 [英] Getting metadata by NSFileManager
问题描述
我正在与NSFileManager一起使用,我能够获取文件的最新更新,创建日期等信息,但是我无法获取文件的上次打开时间.有什么方法可以获取这些信息?
I am working with NSFileManager and I am able to get the file's last update, creation date, ... but I am not able to get when was the last time the file was opened. Is there any way to get this information?
还有另一个问题,我通过pathExtension属性获得了MIME,但是通过这种方式,我得到了例如.pdf,.doc等...,而不是application/pdf,application/doc,text/txt,audio/vmw, ...有什么方法可以自动获取此信息?
And other question, I get the MIME by the pathExtension property, but this way I get for example .pdf, .doc, ... instead of application/pdf, application/doc, text/txt, audio/vmw, ...is any way to get this information automatically?
非常感谢!
推荐答案
使用Spotlight的MDItem API获取所有信息
Use Spotlight's MDItem API to get all the info
NSString *path = @"/Users/dominik/Downloads/Screen Shot 2013-11-28 at 13.26.04.png";
MDItemRef item = MDItemCreate(NULL, (CFStringRef)path);
NSArray *attributes = (NSArray*)CFBridgingRelease(MDItemCopyAttributeNames(item));
NSDate *date = (NSDate*)CFBridgingRelease(MDItemCopyAttribute(item, kMDItemLastUsedDate));
CFRelease(item);
NSLog(@"%@",attributes);
NSLog(@"%@",date);
这篇关于通过NSFileManager获取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!