【问题标题】:Get the Date, when the file was added to the mobile documents folder?获取文件添加到移动文档文件夹的日期?
【发布时间】:2012-01-14 13:26:59
【问题描述】:

是否有可能/是否有文件属性来获取日期,何时将文件添加到移动文档文件夹/icloud?

【问题讨论】:

  • 会不会是文件的NSFileCreationDate属性看NSFileManager - attributesOfItemAtPath
  • 在 Mac 上 ...不,NSFileCreationDate 仅在我创建新文件时才有效,但如果您将文件复制/移动到文件夹中,那将不起作用。

标签: objective-c cocoa icloud


【解决方案1】:

我在 stackoverflow 的另一个问题中找到了答案:

Where does the Finder obtain the "date added" of an item in a folder?

添加日期的属性在 Spotlight 元数据中:

NSDate *dateAdded(NSURL *url)
{
    NSDate *rslt = nil;
    MDItemRef inspectedRef = nil;

    inspectedRef = MDItemCreateWithURL(kCFAllocatorDefault, (CFURLRef)url);
    if (inspectedRef){
        CFTypeRef cfRslt = MDItemCopyAttribute(inspectedRef, (CFStringRef)@"kMDItemDateAdded");
        if (cfRslt) {
            rslt = (NSDate *)cfRslt;
        }
    }
    return rslt;
}

【讨论】:

    猜你喜欢
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多