Gre*_*tic 7 iphone cocoa-touch objective-c nsfilemanager ios
我打算编写一些代码,其逻辑基于在我的应用程序的Documents文件夹中测试特定文件的创建日期.事实证明,当我调用 - [NSFileManager attributesOfItemAtPath:error:]时,NSFileCreationDate不是提供的属性之一.
有没有办法发现文件的创建日期?
谢谢.
fileCreationDate确实是字典的一部分.这是一个传递文件URI并从文件中获取一些属性的方法:
- (NSDictionary *) attributesForFile:(NSURL *)anURI {
// note: singleton is not thread-safe
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *aPath = [anURI path];
if (![fileManager fileExistsAtPath:aPath]) return nil;
NSError *attributesRetrievalError = nil;
NSDictionary *attributes = [fileManager attributesOfItemAtPath:aPath
error:&attributesRetrievalError];
if (!attributes) {
NSLog(@"Error for file at %@: %@", aPath, attributesRetrievalError);
return nil;
}
NSMutableDictionary *returnedDictionary =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
[attributes fileType], @"fileType",
[attributes fileModificationDate], @"fileModificationDate",
[attributes fileCreationDate], @"fileCreationDate",
[NSNumber numberWithUnsignedLongLong:[attributes fileSize]], @"fileSize",
nil];
return returnedDictionary;
}Run Code Online (Sandbox Code Playgroud)