原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/1570
原问题描述:
开发了一个IOS应用,在文档目录中有一些文件,需要检测这些文件是否被编辑或者更改过。不知道应该怎么实现?还有如果获取最后一次修改的时间?
解决方案:
下面的代码可以得到文件修改时间:
NSFileManager* fileManager = [NSFileManager defaultManager];
NSDictionary* attributes = [fileManager attributesOfItemAtPath:path error:nil];
if (attributes != nil) {
NSDate *date = (NSDate*)[attributes objectForKey:NSFileModificationDate];
NSLog(@"Last modification date: %@", [date description]);
} else {
NSLog(@"Not found");
}
点击这里,是attributesOfItemAtPath:error:`函数的说明。
点击这里,是文件属性的说明列表