在Cocoa中查找文件的上次修改日期

Mob*_*obX 6 cocoa

如何在cocoa中找到文件的上次修改日期?

dic*_*ciu 6

查看NSFileManager

- (NSDictionary *)fileAttributesAtPath:(NSString *)path traverseLink:(BOOL)flag
Run Code Online (Sandbox Code Playgroud)

你感兴趣的关键是NSFileModificationDate.

  • 这在10.5中已弃用,而是使用 - (NSDictionary*)attributesOfItemAtPath:(NSString*)路径错误:(NSError**)错误 (10认同)

UJe*_*Jey 5

只是为了更新代码:

NSString * path = ... your path here ...
NSDate * fileLastModifiedDate = nil;

NSError * error = nil;
NSDictionary * attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
if (attrs && !error)
{
    fileLastModifiedDate = [attrs fileModificationDate];
}
Run Code Online (Sandbox Code Playgroud)