尝试在 Objective-C 中读取文件的创建日期属性时出错



我试图读取计算机中文件的创建日期属性,我使用以下代码行:

NSError *error = [[NSError alloc] init];
NSDictionary *localFileProperties = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error:&error];
NSLog(@"file date: %@",[localFileProperties fileModificationDate]);

但是我得到一个(null)作为答案,我不知道我做错了什么,我没有收到错误,当我检查NSDictionary描述时,它只有这5个键:

Printing description of localFileProperties:
{
    NSFileSystemFreeNodes = 113416750;
    NSFileSystemFreeSize = 464555008000;
    NSFileSystemNodes = 121886742;
    NSFileSystemNumber = 16777218;
    NSFileSystemSize = 499248103424;
}

我的代码中是否缺少某些内容?或者它可能有什么问题?

查看方法名称或文档。 attributesOfFileSystemForPath:适用于文件系统,而不是单个文件。

你想要attributesOfItemAtPath:error:.

最新更新