NSString *strPath =[[NSBundle mainBundle] pathForResource:@"lomo.jpg" ofType:nil];
NSLog(@"path:%@", strPath);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path = strPath;//@"/tmp/List";
NSError *error = nil;
NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:path error:&error];
if (fileAttributes != nil) {
NSNumber *fileSize = [fileAttributes objectForKey:NSFileSize];
NSString *fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName];
NSDate *fileModDate = [fileAttributes objectForKey:NSFileModificationDate];
NSDate *fileCreateDate = [fileAttributes objectForKey:NSFileCreationDate];
if (fileSize) {
NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]);
}
if (fileOwner) {
NSLog(@"Owner: %@\n", fileOwner);
}
if (fileModDate) {
NSLog(@"Modification date: %@\n", fileModDate);
}
if (fileCreateDate) {
NSLog(@"create date:%@\n", fileModDate);
}
}
else {
NSLog(@"Path (%@) is invalid.", path);
}
本文介绍如何使用Objective-C通过NSFileManager获取指定文件的各种属性,包括文件大小、所有者、修改日期及创建日期。
276

被折叠的 条评论
为什么被折叠?



