iOS:如何找到文件的创建日期? [英] iOS: How do you find the creation date of a file?
问题描述
我正在尝试查找文件的创建日期(NOT修改日期)。
I'm trying to find the creation date (NOT modification date) of a file.
创建日期似乎不在文件的属性中虽然修改日期是。
Creation date doesn't appear to be in the attributes of a file, though modified date is.
我正在使用此代码..
I'm using this code..
NSFileManager* fm = [NSFileManager defaultManager];
NSString* path = [PathHelpers pathInDocumentsFolderWithFilename:FILE_NAME];
NSDictionary* attrs = [fm attributesOfItemAtPath:path error:nil];
if (attrs != nil) {
return (NSDate*)[attrs objectForKey: NSFileCreationDate];
} else {
return nil;
}
总是返回nil。在调试器中键入po attrs以获取NSDictionary中的键/值对列表,返回以下内容。
This always returns nil. Typing 'po attrs' into the debugger to get the list of key/value pairs in the NSDictionary returns the following..
NSFileGroupOwnerAccountID = 20 ;
NSFileGroupOwnerAccountName = staff;
NSFileModificationDate = 2010-01-21 11:47:55 +0000;
NSFileOwnerAccountID = 501;
NSFileOwnerAccountName = ben;
NSFilePosixPermissions = 420;
NSFileReferenceCount = 1;
NSFileSize = 338;
NSFileSystemFileNumber = 2234;
NSFileSystemNumber = 42553324;
NSFileType = NSFileTypeRegular;
NSFileGroupOwnerAccountID = 20;
NSFileGroupOwnerAccountName = staff;
NSFileModificationDate = 2010-01-21 11:47:55 +0000;
NSFileOwnerAccountID = 501;
NSFileOwnerAccountName = ben;
NSFilePosixPermissions = 420;
NSFileReferenceCount = 1;
NSFileSize = 338;
NSFileSystemFileNumber = 2234;
NSFileSystemNumber = 42553324;
NSFileType = NSFileTypeRegular;
没有创建日期.. bah ..
No creation date.. bah..
任何人都知道获得创建日期的另一种方式,还是仅在iOS中不存在?
Anyone know another way of getting the creation date or does it just not exist in iOS?
推荐答案
这段代码实际上是给我很好的创建日期:
This code actually returns the good creation date to me:
NSFileManager* fm = [NSFileManager defaultManager];
NSDictionary* attrs = [fm attributesOfItemAtPath:path error:nil];
if (attrs != nil) {
NSDate *date = (NSDate*)[attrs objectForKey: NSFileCreationDate];
NSLog(@"Date Created: %@", [date description]);
}
else {
NSLog(@"Not found");
}
您是否在App中创建文件?也许这就是问题所在。
Are you creating the file inside the App? Maybe that's where the problem is.
这篇关于iOS:如何找到文件的创建日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!