无法获取FileCreationDate?

时间:2009-07-16 22:37:35

标签: iphone cocoa-touch

在我的应用程序中,我创建了一个目录,然后以下代码可以运行:

NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:trackDirectory traverseLink:YES];
NSDate *fileDate = [fileAttributes objectForKey:NSFileModificationDate];

但是,当我尝试获取NSFileCreationDate时,它不起作用。

我做错了什么?

3 个答案:

答案 0 :(得分:1)

据我所知,iPhoneOS上没有其他日期。以下是整个attributesOfItemAtPath:的样子:

{
    NSFileGroupOwnerAccountID = 20;
    NSFileGroupOwnerAccountName = staff;
    NSFileModificationDate = 2009-12-03 21:34:59 -0800;
    NSFileOwnerAccountID = 501;
    NSFileOwnerAccountName = username;
    NSFilePosixPermissions = 420;
    NSFileReferenceCount = 1;
    NSFileSize = 8703;
    NSFileSystemFileNumber = 14066295;
    NSFileSystemNumber = 234881026;
    NSFileType = NSFileTypeRegular;
}

所以,你的答案是......你正试图访问iPhoneOS上没有的字典键。

答案 1 :(得分:1)

不确定何时添加完全,但这取决于iOS版本。我已经在iOS 4.1中对此进行了测试并得到了:

{
    NSFileCreationDate = "2011-09-23 07:20:12 GMT";
    NSFileExtensionHidden = 0;
    NSFileGroupOwnerAccountID = 501;
    NSFileGroupOwnerAccountName = mobile;
    NSFileModificationDate = "2011-09-23 07:20:48 GMT";
    NSFileOwnerAccountID = 501;
    NSFileOwnerAccountName = mobile;
    NSFilePosixPermissions = 420;
    NSFileProtectionKey = NSFileProtectionNone;
    NSFileReferenceCount = 1;
    NSFileSize = 634880;
    NSFileSystemFileNumber = 382807;
    NSFileSystemNumber = 234881027;
    NSFileType = NSFileTypeRegular;
}

答案 2 :(得分:0)

It depends on iOS version. iOS 5 provides following detail 
{
  NSFileCreationDate = "2012-05-14 09:59:24 +0000";
  NSFileExtensionHidden = 0;
  NSFileGroupOwnerAccountID = 20;
  NSFileGroupOwnerAccountName = staff;
  NSFileModificationDate = "2012-05-14 09:59:29 +0000";
  NSFileOwnerAccountID = 501;
  NSFileOwnerAccountName = indianic;
  NSFilePosixPermissions = 420;
  NSFileReferenceCount = 1;
  NSFileSize = 464357;
  NSFileSystemFileNumber = 1732968;
  NSFileSystemNumber = 234881027;
  NSFileType = NSFileTypeRegular;
}