有没有办法用修改日期的顺序显示文档目录中的文件

时间:2010-03-15 12:18:10

标签: iphone

我只是想知道有一种方法可以使用修改日期的顺序显示文档目录中的文件。

欢迎任何评论

由于

InterDev中

1 个答案:

答案 0 :(得分:3)

NSFileManager类提供对文件属性的访问。

NSFileManager* manager = [NSFileManager defaultManager];
for (NSString *path in [manager contentsOfDirectoryAtPath: documentsDirectory error:nil]){
   NSDictionary* modDate = [manager attributesOfItemAtPath:
             [documentsDirectory stringByAppendingPathComponent:path] error:nil];
   NSDate* dateModified = (NSDate*)[modDate objectForKey: NSFileModificationDate];
   if (dateModified)
      NSLog(@"%@ .Date modified: %@", path, dateModified);
}