【发布时间】:2012-01-17 00:07:57
【问题描述】:
我尝试使用 NSFileManager 的 attributesOfItemAtPath。它适用于文件,但不适用于文件夹。尽管在Apple's documentation 中,他们声称它应该适用于文件或文件夹。但如果我在文件夹上调用它,我得到的只是一个 nil 值。
我使用的代码:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDictionary *folderAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:somePath error:nil];
NSLog(@"Creation date: %@", [dateFormatter stringFromDate:[folderAttributes objectForKey:NSFileCreationDate]]);
输出对我来说总是空的。我的“somePath”是一个 NSString,格式如下:
file://localhost/Users/username/...
想法?谢谢!
【问题讨论】:
标签: objective-c cocoa nsfilemanager